My solution in Java


  • 1
    D
    public class Solution {
        public boolean isPalindrome(int x) {
            String str = Integer.toString(x);
    		String strArry[] = str.split("");
    		boolean check = true;
    
    		for (int i = 0; i < strArry.length / 2; i++) {
    			if (strArry[i].equals(strArry[strArry.length - 1-i])) {
    				check = true;
    			} else {
    				check = false;
    				break;
    			}
    		}
    
    		return check;
        }
    }
    

  • 0
    C

    hi!brother,there can not be extra space!:)


  • 0
    J

    @dong-joo I have something similar to this but I had to put extra checks for strArry.lenght ==2. Because you can have "11" or "-1" to give some examples. You're doing good though!!


Log in to reply
 

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