My simple 132ms c# code


  • 0
    S

    public class Solution {
    public bool IsPalindrome(string s) {
    if(s.Length<2)
    return true;

        	int j = 0;
    		char[] c= s.ToLower ().ToCharArray();
    		for (int i = 0; i < s.Length; i++) {
    			if((int)c [i] > 96 && (int)c [i] < 123||(int)c [i] > 47 && (int)c [i] < 58)  {
    				c [j++] = c [i];
    			}
    		}
    		int p = j - 1, q = 0;
    		while(q<p){
    			if ((int)c [p--] != (int)c [q++])
    				return false;
    		}
    		return true;
    
    }
    

    }


Log in to reply
 

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