目前又攢夠了一件T恤的積分梭纹,終于不用每天守著拿積分了姥敛,于是今天很隨意的選了一道會員簡單題浆劲,再也不用擔心浪費得積分的機會了砂沛,一行流秒之
1165. 單行鍵盤
# @param {String} keyboard
# @param {String} word
# @return {Integer}
def calculate_time(keyboard, word)
(0...word.length-1).to_a.map {|it| (keyboard.index(word[it+1]) - keyboard.index(word[it])).abs}.reduce(keyboard.index(word[0])-0,:+)
end