Simplify the process of finding the minimum length

This commit is contained in:
Ivan R. 2022-11-26 11:47:43 +05:00
parent d09a4d3eb0
commit bb2ac41656
No known key found for this signature in database
GPG key ID: 56C7BAAE859B302C

View file

@ -2,12 +2,7 @@
# @return {String} # @return {String}
def longest_common_prefix(strs) def longest_common_prefix(strs)
# Find min length # Find min length
min_length = strs[0].length min_length = strs.map{|s| s.length}.min()
strs.each do |st|
if st.length < min_length
min_length = st.length
end
end
res = "" res = ""
for i in 0..min_length - 1 do for i in 0..min_length - 1 do