Skip to content

Commit 0f61364

Browse files
authored
Merge pull request DaleStudy#697 from hancrysta1/main
[sj] Week 1
2 parents bcde25c + 6f49d2a commit 0f61364

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

contains-duplicate/hancrysta1.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

valid-palindrome/hancrysta1.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}

0 commit comments

Comments
 (0)