Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions contains-duplicate/hancrysta1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import java.util.*;
class Solution {
public boolean containsDuplicate(int[] nums) {
Set<Integer> numSet = Arrays.stream(nums).boxed().collect(Collectors.toSet());
if(numSet.size()!=nums.length) return true;
else return false;
}
}
17 changes: 17 additions & 0 deletions top-k-frequent-elements/hancrysta1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.*;
class Solution {
public int[] topKFrequent(int[] nums, int k) {
Map<Integer,Integer> count = new HashMap<>();
for(int i=0;i<nums.length;i++){
count.put(nums[i],count.getOrDefault(nums[i],0)+1);
}
List<Integer> sortedCount = new ArrayList<>(count.keySet());
sortedCount.sort((a,b)->count.get(b)-count.get(a));//value 기준 키 정렬
int[] answer = new int[k];
for(int i=0;i<k;i++){
answer[i] = sortedCount.get(i);
}

return answer;
}
}
18 changes: 18 additions & 0 deletions valid-palindrome/hancrysta1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.util.*;
class Solution {
public boolean isPalindrome(String s) {
String words = s.toLowerCase().replaceAll("[^0-9A-Za-z]","");
//System.out.println(words);
Deque<Character> stack = new ArrayDeque<>();
for(int i=0;i<words.length();i++){
stack.push(words.charAt(i));
}
while(!stack.isEmpty()){
for(int i=0;i<words.length();i++){
if(words.charAt(i)==stack.pop()) continue;
else return false;
}
}
return true;
}
}
Loading