Simplify the process of finding the minimum length
This commit is contained in:
parent
d09a4d3eb0
commit
bb2ac41656
1 changed files with 1 additions and 6 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue