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
24 changes: 24 additions & 0 deletions longest-substring-without-repeating-characters/hyejj19.ts
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Sliding Window, Hash Map / Hash Set
  • 설명: 이 코드는 연속된 문자열 구간을 탐색하며 중복을 체크하기 위해 슬라이딩 윈도우와 해시 맵을 사용합니다. 윈도우의 좌우 포인터를 조절하며 최장 길이를 찾는 방식입니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function lengthOfLongestSubstring(s: string): number {
if (s.length <= 1) return s.length;

let left = 0;
let right = 0;
let maxLen = -1;
const sMap = new Map();
while (right !== s.length) {
const curS = s[right];
// Map에 존재하지 않는다 -> 중복 X -> right 전진
if (!sMap.get(curS)) {
sMap.set(s[right], 1);
right++;
} else {
// Map에 존재 한다 -> 중복 O -> left 전진
while (left <= right && sMap.get(curS)) {
sMap.set(s[left], sMap.get(s[left]) - 1);
left++;
}
}
maxLen = Math.max(maxLen, right - left);
}
return maxLen;
}
42 changes: 42 additions & 0 deletions number-of-islands/hyejj19.ts
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: DFS
  • 설명: 이 코드는 재귀 호출을 통해 섬을 탐색하는 방식으로, 깊이 우선 탐색(DFS) 패턴에 속합니다. 인접한 '1'들을 방문하며 섬의 영역을 찾는 구조입니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// sc : O(n*m)
// tc : O(n*m)
function numIslands(grid: string[][]): number {
let count = 0;
const visited = Array.from({length: grid.length}, () =>
Array.from({length: grid[0].length}, () => false),
);
const directions = [
[-1, 0],
[1, 0],
[0, -1],
[0, 1],
];

function explore(x, y) {
visited[x][y] = true;
for (let [dx, dy] of directions) {
const nx = dx + x;
const ny = dy + y;
if (
nx < grid.length &&
ny < grid[0].length &&
nx >= 0 &&
ny >= 0 &&
!visited[nx][ny] &&
grid[nx][ny] === '1'
) {
explore(nx, ny);
}
}
}

for (let x = 0; x < grid.length; x++) {
for (let y = 0; y < grid[x].length; y++) {
if (!visited[x][y] && grid[x][y] === '1') {
count++;
explore(x, y);
}
}
}
return count;
}
18 changes: 18 additions & 0 deletions reverse-linked-list/hyejj19.ts
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers
  • 설명: 이 코드는 두 포인터(prev, cur)를 활용하여 연결 리스트를 역순으로 뒤집는 방식으로, 포인터 이동을 통해 리스트를 순차적으로 처리하는 Two Pointers 패턴에 속합니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
time complexity : O(n)
space complexity : O(1)
*/
function reverseList(head: ListNode | null): ListNode | null {
let prev = null;
let cur = head;
let next = null;

while (cur !== null) {
next = cur.next;
cur.next = prev;
prev = cur;
cur = next;
}

return prev;
}
Loading