728x90
반응형
문제
반응형
풀이
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import java.util.HashSet;
import java.util.Iterator;
class Solution {
public int solution(int[] sides) {
int answer = 0;
HashSet<Integer> s=new HashSet<Integer>();
int max=Math.max(sides[0], sides[1]); //매개변수로 들어온 삼각형의 두 변중에 큰변을 먼저 찾음
int abs=Math.abs(sides[0]-sides[1]);
int i=abs+1;
while(i<=max) {
s.add(i);
i++;
}
int j=max;
while(j<sides[0]+sides[1]) {
s.add(j);
j++;
}
Iterator<Integer> it=s.iterator();
while(it.hasNext()) {
it.next();
answer+=1;
}
return answer;
}
}
|
cs |
728x90
반응형
'[JAVA] 프로그래머스 스쿨 > Java Lv.0' 카테고리의 다른 글
[프로그래머스/Java] Lv.0 저주의 숫자 3 (0) | 2022.12.10 |
---|---|
[프로그래머스/Java] Lv.0 외계어 사전 (1) | 2022.12.07 |
[프로그래머스/Java] Lv.0 숨어있는 숫자의 덧셈 (2) (0) | 2022.12.06 |
[프로그래머스/Java] Lv.0 다항식 더하기 (0) | 2022.12.06 |
[프로그래머스/Java] Lv.0 최댓값 만들기 (2) (0) | 2022.12.02 |