Leetcode 14. Longest Common Prefix

Find the longest common prefix in a string array.

This question has no issue for me. Maybe it’s time to write “medium” question.

# @param {String[]} strs
# @return {String}
def longest_common_prefix(strs)
unless strs.empty?
runtimes = strs[0].length
result = ""
for i in 0..runtimes-1
flag = true
standard = strs[0][i]
strs.each do |str|

unless str[i].eql? standard
return result
end
end
result += standard if flag
end

return result
else
return ""
end
end
Like what you read? Give Roger Wang a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.