Accepted: 138 ms C# solution


  • 0
    D
    public class Solution {
        public bool IsPalindrome(string s) {
            if(string.IsNullOrEmpty(s)) return true;
            
            s = s.ToLower();
            int si = 0, ei = s.Length - 1;
            while(si < ei) {
                if(!this.IsAplphanumeric(s[si])) {
                    ++si;
                    continue;
                }
                if(!this.IsAplphanumeric(s[ei])) {
                    --ei;
                    continue;
                }
                if(s[si++] != s[ei--]) {
                    return false;
                }
            }
            return true;
        }
        
        private bool IsAplphanumeric(char c) {
            return ('a' <= c && c <='z') || ('0' <= c && c<= '9');
        }
    }
    

Log in to reply
 

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