My easy Java Solution runtime beats 97.37 % submissions.


  • 0
    C
        public boolean isHappy(int n) {
        	int result=n;
        	boolean isOne = false;
            for(int i=0;i<10;i++){
            	result = splitDigitSum(result);
            	if(result==1){
            		isOne = true;
            		break;
            	}
            }
            return isOne;
        }
        
        public int splitDigitSum(int num){
        	int sum = 0;
        	int temp = num;
        	while(temp>0){
        		int digit = temp%10;
        		temp /=10;
        		sum+=digit*digit;
        	}
        	return sum;
        }
    

Log in to reply
 

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