diff --git a/contains-duplicate/hancrysta1.java b/contains-duplicate/hancrysta1.java new file mode 100644 index 000000000..9a9e3cfc6 --- /dev/null +++ b/contains-duplicate/hancrysta1.java @@ -0,0 +1,8 @@ +import java.util.*; +class Solution { + public boolean containsDuplicate(int[] nums) { + Set numSet = Arrays.stream(nums).boxed().collect(Collectors.toSet()); + if(numSet.size()!=nums.length) return true; + else return false; + } +} diff --git a/top-k-frequent-elements/hancrysta1.java b/top-k-frequent-elements/hancrysta1.java new file mode 100644 index 000000000..dab94ffa5 --- /dev/null +++ b/top-k-frequent-elements/hancrysta1.java @@ -0,0 +1,17 @@ +import java.util.*; +class Solution { + public int[] topKFrequent(int[] nums, int k) { + Map count = new HashMap<>(); + for(int i=0;i 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 stack = new ArrayDeque<>(); + for(int i=0;i