Beats around 23% JAVA Solution


  • 0
    R
        public boolean isPalindrome(String s) {
            
            StringBuffer sb = new StringBuffer();
            char[] c = s.toCharArray();
            for (char cc : c) {
                if (Character.getNumericValue(cc) >= 0 && Character.getNumericValue(cc) <= 9
                        || Character.getNumericValue(cc) >= 10 && Character.getNumericValue(cc) <= 35) {
                    sb.append(cc);
                }
            }
            String clean = sb.toString().toLowerCase();
            int start = 0;
            int end = clean.length() - 1;
            while (start < end) {
                if (clean.charAt(start) != clean.charAt(end)) {
                    return false;
                }
                start++;
                end--;
            }    
            return true;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.