From bb2ac4165686768640a9b316c95c2ca8d5c72709 Mon Sep 17 00:00:00 2001 From: Ivan Reshetnikov Date: Sat, 26 Nov 2022 11:47:43 +0500 Subject: [PATCH] Simplify the process of finding the minimum length --- problems/14-longest-common-prefix/main.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/problems/14-longest-common-prefix/main.rb b/problems/14-longest-common-prefix/main.rb index 1aec2df..2ec1842 100644 --- a/problems/14-longest-common-prefix/main.rb +++ b/problems/14-longest-common-prefix/main.rb @@ -2,12 +2,7 @@ # @return {String} def longest_common_prefix(strs) # Find min length - min_length = strs[0].length - strs.each do |st| - if st.length < min_length - min_length = st.length - end - end + min_length = strs.map{|s| s.length}.min() res = "" for i in 0..min_length - 1 do