72 ms C++ solution


  • 0
    K
        int temp;
        int multiplier=1;
        int counter=1;
        
        if(x<0) return false;
        
        temp = x;
        
        if(x>=0 && x<=9) return true;
        while(temp>9) {
            temp=temp/10;
            multiplier=multiplier*10;
        }
        int front = x;
        while(counter<=multiplier) {
            int end = x%10;
            int start = front/multiplier;
            
            if(start!=end) return false;
            
            x = x/10;
            front = front % multiplier;
            counter = counter*10;
            multiplier = multiplier/10;
        }
    
        return true;
        
    }

Log in to reply
 

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