uploaded at 2022. 12. 17. 오후 9:35:29
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
// [문제 링크]: https://school.programmers.co.kr/learn/courses/30/lessons/12943
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public int solution(long num) {
|
||||||
|
int answer = 0;
|
||||||
|
for(int i = 0; i < 501; i++){
|
||||||
|
if(num == 1){
|
||||||
|
answer = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(i== 500) {
|
||||||
|
answer = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(num%2==0) num /= 2;
|
||||||
|
else num = 3 * num + 1;
|
||||||
|
}
|
||||||
|
return answer;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user