数字问题

题目

代码

public class Solution {
    /**
     * @param n: the number n 
     * @return: the times n convert to 1
     */
    public int digitConvert(int n) {
        // Write your code here 
        int total=0;
        while (n!=1){
            if(((n&1)==1)){
                n=3*n+1;
            }else {
                n=n/2;
            }
            total++;
        }   
        return total;
    }
}
posted @ 2018-04-04 16:41  baixiaoshuai  阅读(117)  评论(0编辑  收藏  举报