Will every number be smaller than 10 some time later


  • 0
    L

    I have solved this problem, but I want to know "Will every number be smaller than 10 some time later".

    For example, input 17, the process is 17, 50, 25, 29, 85, 89, 145, 42, 20, 4, ……

    input 23, the process is 23, 13, 10, 1

    But is it true for all numbers?

    Here is my code

    bool isHappy(int n) {
    int temp = 10;
    while ( temp >= 10) {
    	temp = 0;
    	while ( n != 0 ) {
    		temp += (n%10)*(n%10);
    		n = n/10;
    	}
    	n = temp;
    }
    return temp==7 || temp==1;
    

    }

    Thank you for your answer. ^_^


  • 0
    T

    Your answer is kind of cheating lol......


  • 0
    L

    What do you mean?


Log in to reply
 

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