Map [1]
Operation | Time Complexity |
---|---|
Access | O(log n) |
Search | O(log n) |
Insertion | O(n) for <= 32 elements, O(log n) for > 32 elements [2] |
Deletion | O(n) for <= 32 elements, O(log n) for > 32 elements |
.git | |
.gitignore | |
# Created by https://www.gitignore.io/api/git,ruby,rails,jetbrains+all | |
# Edit at https://www.gitignore.io/?templates=git,ruby,rails,jetbrains+all | |
### Git ### | |
# Created by git for backups. To disable backups in Git: | |
# $ git config --global mergetool.keepBackup false | |
*.orig |
[ | |
{ | |
"city": "New York", | |
"growth_from_2000_to_2013": "4.8%", | |
"latitude": 40.7127837, | |
"longitude": -74.0059413, | |
"population": "8405837", | |
"rank": "1", | |
"state": "New York" | |
}, |
#!/bin/sh | |
# Userland mode (~$USER/), (~/). | |
# ~/.fonts is now deprecated and that | |
#FONT_HOME=~/.fonts | |
# ~/.local/share/fonts should be used instead | |
FONT_HOME=~/.local/share/fonts | |
echo "installing fonts at $PWD to $FONT_HOME" | |
mkdir -p "$FONT_HOME/adobe-fonts/source-code-pro" |
namespace :db do | |
desc 'Reset counter cache of tasks count in project.' | |
task update_tasks: :environment do | |
print '開始更新任務數' | |
Project.all.each do |p| | |
Project.reset_counters(p.id, :tasks) | |
print '.' | |
end | |
puts '更新完成!' | |
end |
create_table "projects", force: :cascade do |t| | |
t.string "name" | |
t.datetime "created_at", null: false | |
t.datetime "updated_at", null: false | |
t.integer "tasks_count", default: 0 | |
end | |
create_table "tasks", force: :cascade do |t| | |
t.string "name" | |
t.integer "project_id" | |
t.datetime "created_at", null: false |
console.log(primeString("asdf")); // should be true | |
console.log(primeString("abac")); // should be true | |
console.log(primeString("qiuefgqiuefgqiuefg")); // should be false | |
console.log(primeString("zkvjhuj")); // should be true |
function primeString(s, count = 1) { | |
// 如果字串中有重複的模式,最少也會重複 1 次,故迭代超過字串長度的一半還沒找到就不用找了 | |
if(count > s.length / 2) { return true } | |
// 每次迭代將字串的一小塊,設定為分割陣列的符號 chunk | |
let chunk = s.slice(0, count) | |
// 被 chunk 切過的部分會變成陣列中的空元素,此行判斷是不是能夠將陣列切成重複的小塊 | |
// 如果切完後全部的陣列元素都是空的,代表字串被 chunk 整除,恭喜找到規律。 | |
let grouped = s.split(chunk).every(i => i === '') | |
def prime_string(s) | |
s !~ /^(.+)(\1+)$/ | |
end |
function primeString(s) { | |
return !/^(.+)\1+$/.test(s) | |
} |