programmers_이진 변환 반복하기_java
2023. 4. 1. 18:04ㆍAlgorithm/Programmers
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/12924
class Solution {
public int solution(int n) {
int answer = 0;
answer = search(n);
return answer;
}
public int search(int n){
int left = 0;
int right = 1;
int sum = 1;
int cnt = 0;
while(left <= right){
if(sum <= n){
if(sum == n){
cnt++;
}
right++;
sum+=right;
}else if(sum > n){
sum-= left;
left++;
}
}
return cnt;
}
}
'Algorithm > Programmers' 카테고리의 다른 글
programmers_피보나치 수_java (0) | 2023.04.03 |
---|---|
programmers_구명보트_java (0) | 2023.04.03 |
programmers_이진 변환 반복하기_java (0) | 2023.04.01 |
programmers_디펜스 게임_java (0) | 2023.04.01 |
programmers_무인도 여행_java (0) | 2023.03.30 |