Skip to content

Commit 7c4c547

Browse files
committed
fix: lint 에러 수정
1 parent c2deba0 commit 7c4c547

File tree

5 files changed

+103
-105
lines changed

5 files changed

+103
-105
lines changed

contains-duplicate/suKyoung.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function containsDuplicate1(nums: number[]): boolean {
99
});
1010

1111
return isDuplicate;
12-
}
12+
};
1313

1414
// 2번째 풀이(Set)
1515
function containsDuplicate2(nums: number[]): boolean {
@@ -23,4 +23,4 @@ function containsDuplicate2(nums: number[]): boolean {
2323
}
2424

2525
return false;
26-
}
26+
};

house-robber/suKyoung.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@
1717

1818
// 2번풀이 (dp)
1919
function rob(nums: number[]): number {
20-
if (nums.length <= 1) return nums[0] ?? 0;
21-
22-
const dp: number[] = [];
23-
dp[0] = nums[0];
24-
dp[1] = Math.max(nums[0], nums[1]);
25-
26-
for (let i = 2; i < nums.length; i++) {
27-
dp[i] = Math.max(dp[i - 1], dp[i - 2] + nums[i]);
28-
}
29-
30-
return dp[nums.length - 1];
20+
if (nums.length <= 1) return nums[0] ?? 0;
21+
22+
const dp: number[] = [];
23+
dp[0] = nums[0];
24+
dp[1] = Math.max(nums[0], nums[1]);
25+
26+
for (let i = 2; i < nums.length; i++) {
27+
dp[i] = Math.max(dp[i - 1], dp[i - 2] + nums[i]);
3128
}
32-
29+
30+
return dp[nums.length - 1];
31+
};

longest-consecutive-sequence/suKyoung.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function longestConsecutive2(nums: number[]): number {
2020
}
2121

2222
return max;
23-
}
23+
};
2424

2525
// 2번풀이 (hashSet)
2626
function longestConsecutive(nums: number[]): number {
@@ -43,4 +43,4 @@ function longestConsecutive(nums: number[]): number {
4343
}
4444

4545
return max;
46-
}
46+
};

top-k-frequent-elements/suKyoung.ts

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ type FrequencyMap = Record<number, number>;
44
function topKFrequentCountDown(nums: number[], k: number): number[] {
55
const freqMap = buildFrequencyMap1(nums);
66
return pickTopKDescending(freqMap, k);
7-
}
7+
};
88

99
function buildFrequencyMap1(nums: number[]): FrequencyMap {
1010
const map: FrequencyMap = {};
1111
for (const num of nums) {
1212
map[num] = (map[num] || 0) + 1;
1313
}
1414
return map;
15-
}
15+
};
1616

1717
function pickTopKDescending(freqMap: FrequencyMap, k: number): number[] {
1818
const result: number[] = [];
@@ -33,73 +33,72 @@ function pickTopKDescending(freqMap: FrequencyMap, k: number): number[] {
3333
}
3434

3535
return result;
36-
}
37-
36+
};
3837

3938
// 2번풀이(Bucket Sort)
4039
function topKFrequent(nums: number[], k: number): number[] {
41-
const frequencyMap = buildFrequencyMap2(nums);
42-
const frequencyBuckets = buildFrequencyBuckets(nums.length, frequencyMap);
40+
const frequencyMap = buildFrequencyMap2(nums);
41+
const frequencyBuckets = buildFrequencyBuckets(nums.length, frequencyMap);
4342

44-
return collectTopKFrequent(frequencyBuckets, k);
45-
}
46-
47-
function buildFrequencyMap2(nums: number[]): FrequencyMap {
48-
const freqMap: FrequencyMap = {};
49-
for (const num of nums) {
50-
freqMap[num] = (freqMap[num] || 0) + 1;
51-
}
52-
return freqMap;
43+
return collectTopKFrequent(frequencyBuckets, k);
44+
};
45+
46+
function buildFrequencyMap2(nums: number[]): FrequencyMap {
47+
const freqMap: FrequencyMap = {};
48+
for (const num of nums) {
49+
freqMap[num] = (freqMap[num] || 0) + 1;
5350
}
54-
55-
function buildFrequencyBuckets(
56-
size: number,
57-
freqMap: FrequencyMap
58-
): number[][] {
59-
const buckets: number[][] = Array(size + 1).fill(null).map(() => []);
60-
61-
for (const [numStr, frequent] of Object.entries(freqMap)) {
62-
const num = Number(numStr);
63-
buckets[frequent].push(num);
64-
}
65-
66-
return buckets;
51+
return freqMap;
52+
};
53+
54+
function buildFrequencyBuckets(
55+
size: number,
56+
freqMap: FrequencyMap
57+
): number[][] {
58+
const buckets: number[][] = Array(size + 1)
59+
.fill(null)
60+
.map(() => []);
61+
62+
for (const [numStr, frequent] of Object.entries(freqMap)) {
63+
const num = Number(numStr);
64+
buckets[frequent].push(num);
6765
}
68-
69-
function collectTopKFrequent(buckets: number[][], k: number): number[] {
70-
const result: number[] = [];
71-
72-
for (let i = buckets.length - 1; i >= 0 && result.length < k; i--) {
73-
for (const num of buckets[i]) {
74-
result.push(num);
75-
if (result.length === k) break;
76-
}
66+
67+
return buckets;
68+
};
69+
70+
function collectTopKFrequent(buckets: number[][], k: number): number[] {
71+
const result: number[] = [];
72+
73+
for (let i = buckets.length - 1; i >= 0 && result.length < k; i--) {
74+
for (const num of buckets[i]) {
75+
result.push(num);
76+
if (result.length === k) break;
7777
}
78-
79-
return result;
8078
}
81-
79+
80+
return result;
81+
};
8282

8383
// 3번풀이 (MinHeap)
8484
function topKFrequentHeap(nums: number[], k: number): number[] {
85-
const freqMap: Record<number, number> = {};
86-
87-
for (const num of nums) {
88-
freqMap[num] = (freqMap[num] || 0) + 1;
89-
}
90-
91-
const heap: [number, number][] = [];
92-
for (const [numStr, frequent] of Object.entries(freqMap)) {
93-
const num = Number(numStr);
94-
95-
heap.push([num, frequent]);
96-
heap.sort((a, b) => b[1] - a[1]);
97-
98-
if (heap.length > k) {
99-
heap.pop();
100-
}
85+
const freqMap: Record<number, number> = {};
86+
87+
for (const num of nums) {
88+
freqMap[num] = (freqMap[num] || 0) + 1;
89+
}
90+
91+
const heap: [number, number][] = [];
92+
for (const [numStr, frequent] of Object.entries(freqMap)) {
93+
const num = Number(numStr);
94+
95+
heap.push([num, frequent]);
96+
heap.sort((a, b) => b[1] - a[1]);
97+
98+
if (heap.length > k) {
99+
heap.pop();
101100
}
102-
103-
return heap.map(([num]) => num);
104101
}
105-
102+
103+
return heap.map(([num]) => num);
104+
};

two-sum/suKyoung.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
// 1번째 풀이 (brute force)
22
function twoSum1(nums: number[], target: number): number[] {
3-
for(let i = 0; i < nums.length; i++) {
4-
for (let j = 1; j < nums.length; j++) {
5-
const a = nums[i];
6-
const b = nums[j];
3+
for (let i = 0; i < nums.length; i++) {
4+
for (let j = 1; j < nums.length; j++) {
5+
const a = nums[i];
6+
const b = nums[j];
77

8-
if (a + b === target && i !== j) {
9-
return [i, j];
10-
}
11-
}
8+
if (a + b === target && i !== j) {
9+
return [i, j];
10+
}
1211
}
13-
return [];
12+
}
13+
return [];
1414
};
1515

1616
// 2번째 풀이 (indexOf)
1717
function twoSum2(nums: number[], target: number): number[] {
18-
for (let i = 0; i < nums.length; i++) {
19-
const j = target - nums[i];
20-
const index = nums.indexOf(j);
21-
22-
if (index !== -1 && i !== index) {
23-
return [i, index];
24-
}
18+
for (let i = 0; i < nums.length; i++) {
19+
const j = target - nums[i];
20+
const index = nums.indexOf(j);
21+
22+
if (index !== -1 && i !== index) {
23+
return [i, index];
2524
}
26-
return [];
27-
};
25+
}
26+
return [];
27+
};
2828

2929
// 3번째 풀이 (HashMap)
30-
function twoSum(nums: number[], target: number): number[] {
31-
const map: Record<number, number> = {};
32-
33-
for (let i = 0; i < nums.length; i++) {
34-
const complement = target - nums[i];
30+
function twoSum3(nums: number[], target: number): number[] {
31+
const map: Record<number, number> = {};
32+
33+
for (let i = 0; i < nums.length; i++) {
34+
const complement = target - nums[i];
3535

36-
if (complement in map) {
37-
const j = map[complement];
38-
return [i, j];
39-
} else {
40-
map[nums[i]] = i;
41-
}
36+
if (complement in map) {
37+
const j = map[complement];
38+
return [i, j];
39+
} else {
40+
map[nums[i]] = i;
4241
}
42+
}
4343

44-
return [];
44+
return [];
4545
};

0 commit comments

Comments
 (0)