package com.fishercoder.solutions;

/**
 * 65. Valid Number
 *
 * Validate if a given string is numeric.
 *
 * Some examples: "0" => true " 0.1 " => true "abc" => false "1 a" => false "2e10" => true
 *
 * Note: It is intended for the problem statement to be ambiguous. You should gather all
 * requirements up front before implementing one.
 */

public class _65 {
  /**credit: https://discuss.leetcode.com/topic/9490/clear-java-solution-with-ifs*/
  public static class Solution1 {
    public boolean isNumber(String s) {
      s = s.trim();

      boolean pointSeen = false;
      boolean eSeen = false;
      boolean numberSeen = false;
      boolean numberAfterE = true;
      for (int i = 0; i < s.length(); i++) {
        if ('0' <= s.charAt(i) && s.charAt(i) <= '9') {
          numberSeen = true;
          numberAfterE = true;
        } else if (s.charAt(i) == '.') {
          if (eSeen || pointSeen) {
            return false;
          }
          pointSeen = true;
        } else if (s.charAt(i) == 'e') {
          if (eSeen || !numberSeen) {
            return false;
          }
          numberAfterE = false;
          eSeen = true;
        } else if (s.charAt(i) == '-' || s.charAt(i) == '+') {
          if (i != 0 && s.charAt(i - 1) != 'e') {
            return false;
          }
        } else {
          return false;
        }
      }

      return numberSeen && numberAfterE;
    }
  }

  public static class Solution2 {
    /** credit: https://discuss.leetcode.com/topic/2973/java-solution-with-one-line */
    public boolean isNumber(String s) {
      return s.matches("(\\s*)[+-]?((\\.[0-9]+)|([0-9]+(\\.[0-9]*)?))(e[+-]?[0-9]+)?(\\s*)");
    }
  }
}

@@ -33,342 +33,42 @@
 s;%0A%0A
-/**%0A * 65. Valid Number%0A *%0A * Validate if a given string is numeric.%0A *%0A * Some examples: %220%22 =%3E true %22 0.1 %22 =%3E true %22abc%22 =%3E false %221 a%22 =%3E false %222e10%22 =%3E true%0A *%0A * Note: It is intended for the problem statement to be ambiguous. You should gather all%0A * requirements up front before implementing one.%0A */%0A%0Apublic class _65 %7B%0A  /**
+public class _65 %7B%0A    /**%0A     * 
 cred
@@ -139,19 +139,27 @@
 with-ifs
+%0A     
 */%0A
+  
   public
@@ -184,16 +184,20 @@
 tion1 %7B%0A
+    
     publ
@@ -224,24 +224,30 @@
 String s) %7B%0A
+      
       s = s.
@@ -255,16 +255,22 @@
 rim();%0A%0A
+      
       bo
@@ -292,32 +292,38 @@
  = false;%0A      
+    
+  
 boolean eSeen = 
@@ -321,32 +321,38 @@
  eSeen = false;%0A
+      
       boolean nu
@@ -371,24 +371,30 @@
 alse;%0A      
+  
+    
 boolean numb
@@ -406,24 +406,30 @@
 erE = true;%0A
+      
       for (i
@@ -457,24 +457,32 @@
 h(); i++) %7B%0A
+        
         if (
@@ -531,24 +531,34 @@
 %7B%0A          
+  
+        
 numberSeen =
@@ -566,32 +566,42 @@
 true;%0A          
+  
+        
 numberAfterE = t
@@ -605,32 +605,40 @@
 = true;%0A        
+ 
+       
 %7D else if (s.cha
@@ -656,32 +656,42 @@
 .') %7B%0A          
+   
+       
 if (eSeen %7C%7C poi
@@ -704,32 +704,44 @@
 ) %7B%0A            
+   
+         
 return false;%0A  
@@ -730,32 +730,42 @@
   return false;%0A
+          
           %7D%0A    
@@ -752,32 +752,42 @@
               %7D%0A
+          
           pointS
@@ -790,32 +790,40 @@
 intSeen = true;%0A
+        
         %7D else i
@@ -849,32 +849,42 @@
 e') %7B%0A          
+  
+        
 if (eSeen %7C%7C !nu
@@ -899,32 +899,44 @@
 ) %7B%0A            
+           
+ 
 return false;%0A  
@@ -935,34 +935,53 @@
 alse;%0A          
-%7D%0A
+          %7D%0A         
           number
@@ -966,32 +966,33 @@
                 
+ 
 numberAfterE = f
@@ -1007,16 +1007,26 @@
         
+         
+ 
 eSeen = 
@@ -1023,32 +1023,40 @@
   eSeen = true;%0A
+        
         %7D else i
@@ -1108,24 +1108,34 @@
 %7B%0A          
+ 
+         
 if (i != 0 &
@@ -1166,32 +1166,44 @@
 ) %7B%0A            
+           
+ 
 return false;%0A  
@@ -1202,34 +1202,52 @@
 alse;%0A          
-%7D%0A
+          %7D%0A        
         %7D else %7B
@@ -1247,16 +1247,26 @@
  else %7B%0A
+          
         
@@ -1293,19 +1293,39 @@
     
-%7D%0A      %7D%0A%0A
+        %7D%0A            %7D%0A%0A      
     
@@ -1365,19 +1365,27 @@
 rE;%0A
+    
     %7D%0A
+  
   %7D%0A%0A
+  
   pu
@@ -1418,18 +1418,33 @@
 2 %7B%0A    
+ 
-/*
+   /**%0A         
 * credit
@@ -1512,20 +1512,33 @@
 one-line
- */%0A
+%0A         */%0A    
     publ
@@ -1565,24 +1565,30 @@
 String s) %7B%0A
+      
       return
@@ -1673,16 +1673,22 @@
 %22);%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

refactor 65