8 lines java solution


  • 1
    Y
        s = s.toLowerCase();
        StringBuilder builder = new StringBuilder();
        for(int i = 0; i < s.length(); i++){
            if((s.charAt(i) >= 'a' && s.charAt(i) <= 'z') ||(s.charAt(i) >= '0' && s.charAt(i) <= '9'))
                builder.append(s.charAt(i));
        }
        StringBuilder reverse = builder;
        return builder.toString().equals(reverse.reverse().toString());

  • 0
    H

    You can use Character.isLetterOrDigit() instead of that long if...
    And your solution will need extra space which is also can be improved.


Log in to reply
 

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