Commit a04dcac

mo khan <mo.khan@gmail.com>
2020-08-13 03:24:58
Make palindrome? return truthy value
1 parent 5ad66fb
Changed files (1)
2020
08
2020/08/12/main.rb
@@ -48,21 +48,21 @@ end
 
 class Solution
   def self.palindrome?(string)
-    return "" if string.nil? || string.empty?
+    return false if string.nil? || string.empty?
 
-    string == string.reverse ? string : ""
+    string == string.reverse
   end
 
   def self.run(string)
     max = ""
-
     for l in (0..string.size)
       for r in (l+1..string.size)
-        result = palindrome?(string[l..r])
-        max = result if result.size > max.size
+        candidate = string[l..r]
+        if palindrome?(candidate) && candidate.size > max.size
+          max = candidate
+        end
       end
     end
-
     max
   end
 end