[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ์ซ์์ ํํ (์๋ฐ java)
1. ๋ฌธ์ : https://school.programmers.co.kr/learn/courses/30/lessons/12924?language=java
2. ํ์ด
1๋ถํฐ 14๊น์ง ์์ํ๋ ์ผ์ด์ค๋ฅผ ๋ฌ์ 15๊ฐ ๋๋ฉด answer +1
ํจ์จ์ฑ ์ํด 15๋ณด๋ค ํฌ๋ค๋ฉด break
3. ์ฝ๋
class Solution {
public int solution(int n) {
int answer = 1;
for(int i=1;i<n;i++){
int temp = 0;
for(int j=i;j<n+1;j++){
temp += j;
if(temp == n){
answer += 1;
break;
}
else if(temp>n) break;
}
}
return answer;
}
}
'๐ป Coding Problems Solving > Array | String | Loop' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ๊ทค ๊ณ ๋ฅด๊ธฐ (์๋ฐ java) (0) | 2023.02.22 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ์์ด ๋๋ง์๊ธฐ (์๋ฐ java) (0) | 2022.12.01 |
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ์ด์ง๋ณํ๋ฐ๋ณตํ๊ธฐ (์๋ฐ java) (0) | 2022.11.26 |
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ๋ฌธ์์ด ๋ง๋ค๊ธฐ (์๋ฐ java) (0) | 2022.11.24 |
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ์ต๋๊ฐ๊ณผ ์ต์๊ฐ (์๋ฐ java) (0) | 2022.11.24 |
์ต๊ทผ๋๊ธ