279. 콜라츠 추측

김해준's avatar
Jan 15, 2026
279. 콜라츠 추측

사용언어 : Java

문제
notion image
풀이
class Solution { public int solution(int num) { // int의 max값을 넘어설 가능성이 있기때문에 long형으로 시작 long temp = num; for(int i = 0 ; i < 500; i++) { if(temp == 1){ return i; } if(temp % 2 == 0){ temp /= 2; } else{ temp *= 3; temp += 1; } } return -1; } }
notion image
Share article