프로그래머스LV1 - 콜라츠 추측

Kong-al·2022년 10월 13일
0

프로그래머스LV1 - 콜라츠 추측

[ 답안 ]

class Solution {
	    public long solution(long num) {
	    	long answer = 0;
	        while(num > 1){
	            num =(num%2==0)?num/2:num*3+1;
	            answer++;
	            if(answer > 500) {
	            	answer = -1;
	            	break;
	            }
	        }
	        return answer;
	    }
	}
profile
웹개발 공부중!(❁´◡`❁)

0개의 댓글