問題
https://leetcode.com/problems/longest-common-prefix/
解いた
# @param {String[]} strs # @return {String} def longest_common_prefix(strs) data = strs[0] result = "" data.chars.each_with_index do |char, index| if strs.all? { |str| str[index] == char} result += char else break end end result end
結果