You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

9 lines
215 B
Ruby

# @param {String[]} strs
# @return {String}
def longest_common_prefix(strs)
return '' if strs.empty?
min, max = strs.minmax
idx = min.size.times { |i| break i unless min[i] == max[i] }
min[0...idx]
end