目前又攒够了一件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