Skip to content

Commit 4ac4481

Browse files
committed
Check filename rules 해결 시도
1 parent e48bda1 commit 4ac4481

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

longest-consecutive-sequence/kdh-92.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ public int longestConsecutive(int[] nums) {
3939
}
4040

4141
for(int key : hm.keySet()){
42-
if(hm.containsKey(key - 1)== false){
42+
if(hm.containsKey(key - 1)){
4343
hm.put(key, true);
4444
}
4545
}
4646

4747
int max = 0;
4848
for(int key : hm.keySet()){
4949
int k =1;
50-
if(hm.get(key) == true){
51-
while(hm.containsKey(key + k) == true){
50+
if(hm.get(key)){
51+
while(hm.containsKey(key + k)){
5252
k++;
5353
}
5454
}

top-k-frequent-elements/kdh-92.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,40 +43,40 @@ public int[] topKFrequent(int[] nums, int k) {
4343
// Runtime : 19ms Beats 8.16%
4444
// Memory : 49.00MB Beats 20.01%
4545
// Stream에 익숙해지기 위해 공부용
46-
return Arrays.stream(nums)
47-
.boxed()
48-
.collect(Collectors.groupingBy(num -> num, Collectors.summingInt(num -> 1)))
49-
.entrySet().stream()
50-
.sorted((a, b) -> b.getValue() - a.getValue())
51-
.limit(k)
52-
.mapToInt(Map.Entry::getKey)
53-
.toArray();
46+
return Arrays.stream(nums)
47+
.boxed()
48+
.collect(Collectors.groupingBy(num -> num, Collectors.summingInt(num -> 1)))
49+
.entrySet().stream()
50+
.sorted((a, b) -> b.getValue() - a.getValue())
51+
.limit(k)
52+
.mapToInt(Map.Entry::getKey)
53+
.toArray();
5454

5555
// (3) Array List
5656
// 시간복잡도 : O(N)
5757
// Runtime : 13ms Beats 75.77%
5858
// Memory : 48.44MB Beats 61.68%
59-
Map<Integer, Integer> frequencyMap = new HashMap<>();
60-
for (int num : nums) {
61-
frequencyMap.put(num, frequencyMap.getOrDefault(num, 0) + 1);
62-
}
59+
Map<Integer, Integer> frequencyMap = new HashMap<>();
60+
for (int num : nums) {
61+
frequencyMap.put(num, frequencyMap.getOrDefault(num, 0) + 1);
62+
}
6363

64-
List<Integer>[] buckets = new List[nums.length + 1];
65-
for (int key : frequencyMap.keySet()) {
66-
int freq = frequencyMap.get(key);
67-
if (buckets[freq] == null) {
68-
buckets[freq] = new ArrayList<>();
69-
}
70-
buckets[freq].add(key);
71-
}
64+
List<Integer>[] buckets = new List[nums.length + 1];
65+
for (int key : frequencyMap.keySet()) {
66+
int freq = frequencyMap.get(key);
67+
if (buckets[freq] == null) {
68+
buckets[freq] = new ArrayList<>();
69+
}
70+
buckets[freq].add(key);
71+
}
7272

73-
List<Integer> result = new ArrayList<>();
74-
for (int i = buckets.length - 1; i >= 0 && result.size() < k; i--) {
75-
if (buckets[i] != null) {
76-
result.addAll(buckets[i]);
77-
}
78-
}
73+
List<Integer> result = new ArrayList<>();
74+
for (int i = buckets.length - 1; i >= 0 && result.size() < k; i--) {
75+
if (buckets[i] != null) {
76+
result.addAll(buckets[i]);
77+
}
78+
}
7979

80-
return result.stream().mapToInt(Integer::intValue).toArray();
80+
return result.stream().mapToInt(Integer::intValue).toArray();
8181
}
82-
}
82+
}

0 commit comments

Comments
 (0)