File tree Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Original file line number Diff line number Diff line change 1
- import java .util .*;
1
+ import java .util .HashSet ;
2
+ import java .util .Set ;
3
+
2
4
class SolutionGotprgmer {
3
5
// 해당 문제는 어느 한 숫자가 2개이상 존재할 경우 true를 그렇지 않을 경우, false를 반환하는 문제이다.
4
6
// set을 사용해서 set에 이미 값이 존재한다면 개수가 2 이상이므로 true 그렇지 않으면 false를 출력한다.
@@ -14,20 +16,15 @@ class SolutionGotprgmer {
14
16
public boolean containsDuplicate (int [] nums ) {
15
17
distinctNums = new HashSet <>();
16
18
boolean ans = false ;
17
- for (int checkNum : nums ){
18
- if (distinctNums .contains (checkNum )){
19
+ for (int checkNum : nums ) {
20
+ if (distinctNums .contains (checkNum )) {
19
21
ans = true ;
20
22
break ;
21
23
};
22
24
distinctNums .add (checkNum );
23
25
}
24
26
return ans ;
25
27
}
26
- public static void main (String [] args ){
27
- Solution s = new Solution ();
28
- System .out .println (s );
29
-
30
- }
31
28
32
29
33
- }
30
+ }
You can’t perform that action at this time.
0 commit comments