File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .*;
2
+ class Solution {
3
+ public boolean containsDuplicate (int [] nums ) {
4
+ Set <Integer > numSet = Arrays .stream (nums ).boxed ().collect (Collectors .toSet ());
5
+ if (numSet .size ()!=nums .length ) return true ;
6
+ else return false ;
7
+ }
8
+ }
Original file line number Diff line number Diff line change
1
+ import java .util .*;
2
+ class Solution {
3
+ public int [] topKFrequent (int [] nums , int k ) {
4
+ Map <Integer ,Integer > count = new HashMap <>();
5
+ for (int i =0 ;i <nums .length ;i ++){
6
+ count .put (nums [i ],count .getOrDefault (nums [i ],0 )+1 );
7
+ }
8
+ List <Integer > sortedCount = new ArrayList <>(count .keySet ());
9
+ sortedCount .sort ((a ,b )->count .get (b )-count .get (a ));//value 기준 키 정렬
10
+ int [] answer = new int [k ];
11
+ for (int i =0 ;i <k ;i ++){
12
+ answer [i ] = sortedCount .get (i );
13
+ }
14
+
15
+ return answer ;
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ import java .util .*;
2
+ class Solution {
3
+ public boolean isPalindrome (String s ) {
4
+ String words = s .toLowerCase ().replaceAll ("[^0-9A-Za-z]" ,"" );
5
+ //System.out.println(words);
6
+ Deque <Character > stack = new ArrayDeque <>();
7
+ for (int i =0 ;i <words .length ();i ++){
8
+ stack .push (words .charAt (i ));
9
+ }
10
+ while (!stack .isEmpty ()){
11
+ for (int i =0 ;i <words .length ();i ++){
12
+ if (words .charAt (i )==stack .pop ()) continue ;
13
+ else return false ;
14
+ }
15
+ }
16
+ return true ;
17
+ }
18
+ }
You can’t perform that action at this time.
0 commit comments