Skip to content

[JeonJe] WEEK 07 Solutions - #2796

Open
JeonJe wants to merge 5 commits into
DaleStudy:mainfrom
JeonJe:week7
Open

[JeonJe] WEEK 07 Solutions#2796
JeonJe wants to merge 5 commits into
DaleStudy:mainfrom
JeonJe:week7

Conversation

@JeonJe

@JeonJe JeonJe commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

๋‹ต์•ˆ ์ œ์ถœ ๋ฌธ์ œ

  • reverse-linked-list
  • longest-substring-without-repeating-characters
  • number-of-islands
  • unique-paths
  • set-matrix-zeroes

์ž‘์„ฑ์ž ์ฒดํฌ ๋ฆฌ์ŠคํŠธ

  • Projects์˜ ์˜ค๋ฅธ์ชฝ ๋ฒ„ํŠผ(โ–ผ)์„ ๋ˆŒ๋Ÿฌ ํ™•์žฅํ•œ ๋’ค, Week๋ฅผ ํ˜„์žฌ ์ฃผ์ฐจ๋กœ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.
  • ๋ฌธ์ œ๋ฅผ ๋ชจ๋‘ ํ‘ธ์‹œ๋ฉด ํ”„๋กœ์ ํŠธ์—์„œ Status๋ฅผ In Review๋กœ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.
  • ์ฝ”๋“œ ๊ฒ€ํ† ์ž 1๋ถ„ ์ด์ƒ์œผ๋กœ๋ถ€ํ„ฐ ์Šน์ธ์„ ๋ฐ›์œผ์…จ๋‹ค๋ฉด PR์„ ๋ณ‘ํ•ฉํ•ด์ฃผ์„ธ์š”.

๊ฒ€ํ† ์ž ์ฒดํฌ ๋ฆฌ์ŠคํŠธ

Important

๋ณธ์ธ ๋‹ต์•ˆ ์ œ์ถœ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋‹ค๋ฅธ ๋ถ„ PR ํ•˜๋‚˜ ์ด์ƒ์„ ๋ฐ˜๋“œ์‹œ ๊ฒ€ํ† ๋ฅผ ํ•ด์ฃผ์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค!

  • ๋ฐ”๋กœ ์ด์ „์— ์˜ฌ๋ผ์˜จ PR์— ๋ณธ์ธ์„ ์ฝ”๋“œ ๋ฆฌ๋ทฐ์–ด๋กœ ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š”.
  • ๋ณธ์ธ์ด ๊ฒ€ํ† ํ•ด์•ผํ•˜๋Š” PR์˜ ๋‹ต์•ˆ ์ฝ”๋“œ์— ํ”ผ๋“œ๋ฐฑ์„ ์ฃผ์„ธ์š”.
  • ํ† ์š”์ผ ์ „๊นŒ์ง€ PR์„ ๋ณ‘ํ•ฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์Šน์ธํ•ด์ฃผ์„ธ์š”.

@dalestudy

dalestudy Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

๐Ÿ“Š JeonJe ๋‹˜์˜ ํ•™์Šต ํ˜„ํ™ฉ

์ด๋ฒˆ ์ฃผ ์ œ์ถœ ๋ฌธ์ œ

๋ฌธ์ œ ๋‚œ์ด๋„ ์œ ํ˜• ๋ถ„์„
longest-substring-without-repeating-characters Medium โœ… ์˜๋„ํ•œ ์œ ํ˜•
number-of-islands Medium โœ… ์˜๋„ํ•œ ์œ ํ˜•
reverse-linked-list Easy โœ… ์˜๋„ํ•œ ์œ ํ˜•
unique-paths Medium โœ… ์˜๋„ํ•œ ์œ ํ˜•

๋ˆ„์  ํ•™์Šต ์š”์•ฝ

  • ํ’€์ดํ•œ ๋ฌธ์ œ: 30 / 75๊ฐœ
  • ์ด๋ฒˆ ์ฃผ ์œ ํ˜• ์ผ์น˜์œจ: 100% (4๋ฌธ์ œ ์ค‘ 4๋ฌธ์ œ ์ผ์น˜)

๋ฌธ์ œ ํ’€์ด ํ˜„ํ™ฉ

์นดํ…Œ๊ณ ๋ฆฌ ์ง„ํ–‰๋„ ์™„๋ฃŒ
Array โ– โ– โ– โ– โ– โ– โ–ก 8 / 10 (Medium 5, Easy 3)
Dynamic Programming โ– โ– โ– โ– โ–กโ–กโ–ก 7 / 11 (Easy 1, Medium 6)
Matrix โ– โ– โ– โ– โ–กโ–กโ–ก 2 / 4 (Medium 2)
String โ– โ– โ– โ– โ–กโ–กโ–ก 5 / 10 (Medium 2, Easy 3)
Heap โ– โ– โ–กโ–กโ–กโ–กโ–ก 1 / 3 (Medium 1)
Tree โ– โ– โ–กโ–กโ–กโ–กโ–ก 4 / 14 (Medium 3, Easy 1)
Binary โ– โ–กโ–กโ–กโ–กโ–กโ–ก 1 / 5 (Easy 1)
Linked List โ– โ–กโ–กโ–กโ–กโ–กโ–ก 1 / 6 (Easy 1)
Graph โ– โ–กโ–กโ–กโ–กโ–กโ–ก 1 / 8 (Medium 1)
Interval โ–กโ–กโ–กโ–กโ–กโ–กโ–ก 0 / 5 โ† ์•„์ง ์‹œ์ž‘ ์•ˆ ํ•จ

๐Ÿค– ์ด ๋Œ“๊ธ€์€ GitHub App์„ ํ†ตํ•ด ์ž๋™์œผ๋กœ ์ž‘์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ”ข API ์‚ฌ์šฉ๋Ÿ‰ (gpt-5-nano)
์š”์ฒญ ์ž…๋ ฅ ํ† ํฐ ์ถœ๋ ฅ ํ† ํฐ ํ•ฉ๊ณ„ ๋น„์šฉ
1 294 52 346 $0.000036
2 677 74 751 $0.000063
3 1,212 111 1,323 $0.000105
4 1,641 173 1,814 $0.000151
5 1,557 168 1,725 $0.000145
ํ•ฉ๊ณ„ 5,381 578 5,959 $0.000500

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, Sliding Window, Hash Map / Hash Set
  • ์„ค๋ช…: ์™ผ์ชฝ ํฌ์ธํ„ฐ์™€ ์˜ค๋ฅธ์ชฝ ํฌ์ธํ„ฐ๋ฅผ ์ด์šฉํ•ด ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์˜ ์ค‘๋ณต ์—ฌ๋ถ€๋ฅผ ์ฐฝ ะฟะตั€ะตะฟ๋„˜์œผ๋กœ ๊ด€๋ฆฌํ•˜๋ฉฐ, ์ฐฝ์˜ ํฌ๊ธฐ๋ฅผ ์กฐ์ •ํ•˜๋Š” Sliding Window ํŒจํ„ด์ด๋‹ค. Set์œผ๋กœ ์ค‘๋ณต ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•˜๋ฉฐ ๋‘ ํฌ์ธํ„ฐ๋ฅผ ์กฐ์ •ํ•ด ์ตœ์žฅ ๋ถ€๋ถ„๋ฌธ์ž์—ด ๊ธธ์ด๋ฅผ ๊ฐฑ์‹ ํ•œ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

์œ ์ € ๋ถ„์„ ์‹ค์ œ ๋ถ„์„ ๊ฒฐ๊ณผ
Time O(n) O(n) โœ…
Space O(min(n, m)) O(k) โŒ

ํ”ผ๋“œ๋ฐฑ: ์™ผ์ชฝ ํฌ์ธํ„ฐ์™€ ์˜ค๋ฅธ์ชฝ ํฌ์ธํ„ฐ๋ฅผ ์ด์šฉํ•œ ๋Œ€ํ‘œ์ ์ธ ์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ ์•Œ๊ณ ๋ฆฌ์ฆ˜์œผ๋กœ ์„ ํ˜• ์‹œ๊ฐ„์— ๋™์ž‘ํ•œ๋‹ค. ์ค‘๋ณต์„ ์ œ๊ฑฐํ•˜๊ธฐ ์œ„ํ•ด ํ•ด์‹œ์…‹์„ ์‚ฌ์šฉํ•œ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ํ˜„์žฌ ๊ตฌํ˜„์ด ์ ์ ˆํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.

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, Greedy, Linked List
  • ์„ค๋ช…: ํ•ด๋‹น ์ฝ”๋“œ๋Š” ๋‹จ์ผ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ๋ฅผ ์•ž์—์„œ ๋’ค๋กœ ์ˆœํšŒํ•˜๋ฉฐ ํฌ์ธํ„ฐ๋ฅผ ๋’ค์ง‘๋Š” ๋ฐฉ์‹์œผ๋กœ ๋…ธ๋“œ๋ฅผ ์—ญ์ˆœ์œผ๋กœ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ๋‘ ๊ฐœ์˜ ํฌ์ธํ„ฐ๋ฅผ ์‚ฌ์šฉํ•ด ๊ฐ ๋…ธ๋“œ์˜ ๋ฐฉํ–ฅ์„ ๋ฐ”๊พธ๋Š” ์ผ๋ฐ˜์ ์ธ ๋‘ ํฌ์ธํ„ฐ(๋˜๋Š” ํ•ด์ œ ์ˆœ์„œ ๊ด€๋ฆฌ) ๊ธฐ๋ฒ•์— ํ•ด๋‹นํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

์œ ์ € ๋ถ„์„ ์‹ค์ œ ๋ถ„์„ ๊ฒฐ๊ณผ
Time O(n) O(n) โœ…
Space O(1) O(1) โœ…

ํ”ผ๋“œ๋ฐฑ: ํฌ์ธํ„ฐ ๋‘ ๊ฐœ(๋˜๋Š” ์„ธ ๊ฐœ)๋งŒ์œผ๋กœ ๋…ธ๋“œ์˜ ์—ฐ๊ฒฐ ๋ฐฉํ–ฅ์„ ๋’ค์ง‘์–ด ์ˆœํšŒํ•˜๋ฉฐ ์ฒ˜๋ฆฌํ•œ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ํ˜„์žฌ ๊ตฌํ˜„์ด ์ ์ ˆํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.

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.

๐Ÿท๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํŒจํ„ด ๋ถ„์„

longest-substring-without-repeating-characters/JeonJe.java
import java.util.*;

// TC: O(n)
// SC: O(min(n, m)) (m = ๋ฌธ์ž ์ง‘ํ•ฉ ํฌ๊ธฐ)
class Solution {
    public int lengthOfLongestSubstring(String s) {

        int answer = 0;
        int left = 0;

        Set<Character> temp = new HashSet<>();

        for (int right = 0; right < s.length(); right++) {

            // ์ค‘๋ณต์ด ์‚ฌ๋ผ์งˆ ๋•Œ๊นŒ์ง€ s[left]๋ฅผ set์—์„œ ๋นผ๋ฉฐ left๋ฅผ ์ „์ง„์‹œํ‚จ๋‹ค.
            while (temp.contains(s.charAt(right))) {
                temp.remove(s.charAt(left));
                left++;
            }

            temp.add(s.charAt(right));
            answer = Math.max(answer, right - left + 1);
        }

        return answer;
    }
}
  • ํŒจํ„ด: Two Pointers, Hash Map / Hash Set, Sliding Window
  • ์„ค๋ช…: ๋‘ ํฌ์ธํ„ฐ(left, right)๋กœ ์ฐฝ(window)์„ ํ™•์žฅ/์ถ•์†Œํ•˜๋ฉฐ ์ค‘๋ณต ์ œ๊ฑฐ๋ฅผ ์œ„ํ•ด ํ•ด์‹œ์…‹์œผ๋กœ ๋ฐฉ๋ฌธ ์—ฌ๋ถ€๋ฅผ ์ถ”์ ํ•œ๋‹ค. ์ฐฝ์˜ ๊ธธ์ด๋ฅผ ์ตœ๋Œ€ํ™”ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด ๊ธธ์ด๋ฅผ ๊ตฌํ•˜๋Š” ์ „ํ˜•์ ์ธ Sliding Window ํŒจํ„ด์ด๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

์œ ์ € ๋ถ„์„ ์‹ค์ œ ๋ถ„์„ ๊ฒฐ๊ณผ
Time O(n) O(n) โœ…
Space O(min(n, m)) O(min(m, n)) โŒ

ํ”ผ๋“œ๋ฐฑ: ๋‘ ์ธ๋ฑ์Šค(left, right)๋กœ ์ฐฝ์„ ์œ ์ง€ํ•˜๋ฉฐ ๊ฐ ๋ฌธ์ž๋ฅผ ์ง‘ํ•ฉ์— ๋‹ด์•„ ์ค‘๋ณต ์—ฌ๋ถ€๋ฅผ ๊ฒ€์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๊ฐ ๋ฌธ์ž์— ๋Œ€ํ•ด ํ•œ ๋ฒˆ์”ฉ๋งŒ ์ถ”๊ฐ€/์‚ญ์ œ๋˜๋ฏ€๋กœ ์„ ํ˜• ์‹œ๊ฐ„ ๋ณต์žก๋„๋ฅผ ์–ป์Šต๋‹ˆ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ํ˜„์žฌ ๊ตฌํ˜„์ด ์ ์ ˆํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.

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.

๐Ÿท๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํŒจํ„ด ๋ถ„์„

number-of-islands/JeonJe.java
import java.util.*;

// TC: O(m * n)
// SC: O(m * n)
class Solution {

    private static int[] dx = {0, -1, 0, 1};
    private static int[] dy = {1, 0, -1, 0};

    private int n = 0;
    private int m = 0;

    public int numIslands(char[][] grid) {
        n = grid[0].length;
        m = grid.length;

        boolean[][] visited = new boolean[m][n];

        int answer = 0;

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (!visited[i][j] && grid[i][j] == '1') {
                    answer++;
                    dfs(i, j, grid, visited);
                }
            }
        }
        return answer;
    }

    private void dfs(int x, int y, char[][] grid, boolean[][] visited) {
        visited[x][y] = true;

        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];

            if (0 <= nx && nx < m && 0 <= ny && ny < n && grid[nx][ny] == '1' && !visited[nx][ny]) {
                dfs(nx, ny, grid, visited);
            }
        }
    }
}
  • ํŒจํ„ด: Depth-First Search, Hash Map / Hash Set
  • ์„ค๋ช…: ๊ทธ๋ฆฌ๋“œ์—์„œ 1๋กœ ์—ฐ๊ฒฐ๋œ ์˜์—ญ์„ DFS๋กœ ํƒ์ƒ‰ํ•˜์—ฌ ๋ฐฉ๋ฌธ ์ฒ˜๋ฆฌํ•˜๋ฉฐ ์„น์…˜๋งˆ๋‹ค ์นด์šดํŠธ๋ฅผ ์ฆ๊ฐ€์‹œํ‚ค๋Š” ํ’€์ด๋กœ, ์ธ์ ‘ ๋…ธ๋“œ ํƒ์ƒ‰์€ ์žฌ๊ท€๋ฅผ ์ด์šฉํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

์œ ์ € ๋ถ„์„ ์‹ค์ œ ๋ถ„์„ ๊ฒฐ๊ณผ
Time O(m * n) O(m*n) โœ…
Space O(m * n) O(m*n) โœ…

ํ”ผ๋“œ๋ฐฑ: ๊ทธ๋ฆฌ๋“œ ๋ชจ๋“  ์นธ์„ ํ•œ ๋ฒˆ์”ฉ ๋ฐฉ๋ฌธํ•˜๋ฉฐ, ๋ฐฉ๋ฌธ ์—ฌ๋ถ€๋ฅผ boolean ๋ฐฐ์—ด๋กœ ์ถ”์ ํ•ฉ๋‹ˆ๋‹ค. DFS ์žฌ๊ท€ ๋Œ€์‹  ์Šคํƒ ์‚ฌ์šฉ ์‹œ ๊ณต๊ฐ„ ์‚ฌ์šฉ์ด ๋‹ฌ๋ผ์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ํ˜„์žฌ ๊ตฌํ˜„์ด ์ ์ ˆํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.

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.

๐Ÿท๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํŒจํ„ด ๋ถ„์„

reverse-linked-list/JeonJe.java
import java.util.*;

// TC: O(n)
// SC: O(1)
class Solution {
    public ListNode reverseList(ListNode head) {
        ListNode prev = null;
        ListNode cur = head;

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

        return prev;
    }
}
  • ํŒจํ„ด: Two Pointers, Linked List
  • ์„ค๋ช…: ๋งํฌ๋“œ ๋ฆฌ์ŠคํŠธ๋ฅผ ์—ญ์ˆœ์œผ๋กœ ๋’ค์ง‘๋Š” ๋Œ€ํ‘œ์  ๊ธฐ๋ฒ•์œผ๋กœ, ํฌ์ธํ„ฐ ๋‘ ๊ฐœ๋ฅผ ์‚ฌ์šฉํ•ด ๋…ธ๋“œ๋ฅผ ์ˆœํšŒํ•˜๋ฉฐ ๋ฐฉํ–ฅ์„ ๋ฐ”๊ฟ”๋‚˜๊ฐ€๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค. ๊ณต๊ฐ„ ๋ณต์žก๋„ O(1)์ด๋ฉฐ ํ๋ฆ„์ƒ ๋‘ ํฌ์ธํ„ฐ๋ฅผ ๊ต์ฐจ์‹œํ‚ค๋Š” ํ˜•ํƒœ๋กœ ๊ตฌํ˜„๋ฉ๋‹ˆ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

์œ ์ € ๋ถ„์„ ์‹ค์ œ ๋ถ„์„ ๊ฒฐ๊ณผ
Time O(n) O(n) โœ…
Space O(1) O(1) โœ…

ํ”ผ๋“œ๋ฐฑ: ๋ฌด์—‡๋ณด๋‹ค ๊ธฐ์กด ํฌ์ธํ„ฐ๋ฅผ ์ž„์‹œ๋กœ ์ €์žฅํ•˜์—ฌ ์—ญ์ „์‹œํ‚ค๋Š” ํ‘œ์ค€ ํ’€์ด๋กœ, ์ถ”๊ฐ€ ๊ณต๊ฐ„ ์—†์ด ํ•œ ๋ฒˆ์˜ ์ˆœํšŒ๋กœ ํ•ด๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ํ˜„์žฌ ๊ตฌํ˜„์ด ์ ์ ˆํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.

@ICE0208
ICE0208 self-requested a review August 6, 2026 07:44
Comment thread unique-paths/JeonJe.java

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.

๐Ÿท๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํŒจํ„ด ๋ถ„์„

unique-paths/JeonJe.java
import java.util.*;

// TC: O(m * n)
// SC: O(m * n)
class Solution {
    public int uniquePaths(int m, int n) {

        int[][] arr = new int[m][n];

        int upSide;
        int leftSide;

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (i == 0 && j == 0) {
                    arr[i][j] = 1;
                    continue;
                }

                upSide = i - 1 < 0 ? 0 : arr[i - 1][j];
                leftSide = j - 1 < 0 ? 0 : arr[i][j - 1];
                arr[i][j] = upSide + leftSide;
            }
        }

        return arr[m - 1][n - 1];
    }
}
  • ํŒจํ„ด: Dynamic Programming
  • ์„ค๋ช…: 2์ฐจ์› DP ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•ด ์ขŒ์ƒ๋‹จ์—์„œ ์šฐํ•˜๋‹จ๊นŒ์ง€์˜ ๊ฒฝ๋กœ ์ˆ˜๋ฅผ ๋ˆ„์  ํ•ฉ์œผ๋กœ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค. ๊ฐ ์œ„์น˜์˜ ๊ฐ’์€ ์œ„์ชฝ๊ณผ ์™ผ์ชฝ์˜ ๊ฒฝ๋กœ ์ˆ˜์˜ ํ•ฉ์œผ๋กœ ๊ฒฐ์ •๋˜๋ฉฐ, ์ค‘๋ณต ๊ณ„์‚ฐ ์—†์ด ์ตœ์  ๋ถ€๋ถ„๊ตฌ์กฐ๋ฅผ ์ด์šฉํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

์œ ์ € ๋ถ„์„ ์‹ค์ œ ๋ถ„์„ ๊ฒฐ๊ณผ
Time O(m * n) O(m*n) โœ…
Space O(m * n) O(m*n) โœ…

ํ”ผ๋“œ๋ฐฑ: ๊ฐ ์…€์˜ ๊ฐ’์€ ์œ„์˜ ์…€๊ณผ ์™ผ์ชฝ ์…€์˜ ํ•ฉ์œผ๋กœ ๊ณ„์‚ฐ๋˜๋ฉฐ, ๊ฒฝ๊ณ„ ์ฒ˜๋ฆฌ ์‹œ 0์„ ์‚ฌ์šฉํ•ด ๊ฐ„๋‹จํžˆ ๊ตฌํ˜„ํ–ˆ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ํ˜„์žฌ ๊ตฌํ˜„์ด ์ ์ ˆํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.

Comment thread unique-paths/JeonJe.java

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.

๐Ÿท๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํŒจํ„ด ๋ถ„์„

unique-paths/JeonJe.java
import java.util.*;

// TC: O(m * n)
// SC: O(n)
class Solution {
    public int uniquePaths(int m, int n) {

        int[] arr = new int[n];
        Arrays.fill(arr, 1);

        for (int i = 1; i < m; i++) {
            for (int j = 1; j < n; j++) {
                arr[j] = arr[j] + arr[j - 1];
            }
        }

        return arr[n - 1];
    }
}
  • ํŒจํ„ด: Dynamic Programming, Greedy
  • ์„ค๋ช…: 2์ฐจ์› ๊ฒฉ์ž์—์„œ ์‹œ์ž‘์ ์—์„œ ๋„์ฐฉ์ ๊นŒ์ง€์˜ ๊ฒฝ๋กœ ์ˆ˜๋ฅผ ํ–‰๋ ฌ๋กœ ๊ณ„์‚ฐํ•˜๋Š” ๋ฌธ์ œ๋กœ, ํ•œ ์ค„ ๋ฐฐ์—ด๋กœ ์ตœ์ ํ™”ํ•˜๋Š” DP ๊ธฐ๋ฒ•์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๊ฐ ์…€์˜ ๊ฐ’์€ ์œ„์ชฝ๊ณผ ์™ผ์ชฝ์˜ ๊ฒฝ๋กœ ์ˆ˜์˜ ํ•ฉ์œผ๋กœ ๊ตฌ์„ฑ๋˜๋ฉฐ, ๊ณต๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ค„์ด๊ธฐ ์œ„ํ•ด 1์ฐจ์› ๋ฐฐ์—ด๋กœ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

์œ ์ € ๋ถ„์„ ์‹ค์ œ ๋ถ„์„ ๊ฒฐ๊ณผ
Time O(m * n) O(m * n) โœ…
Space O(n) O(n) โœ…

ํ”ผ๋“œ๋ฐฑ: ๊ฐ ํ–‰๋งˆ๋‹ค ํ˜„์žฌ ์—ด์˜ ๊ฐ’์„ ์ด์ „ ์—ด๊ณผ ๊ฐ™์€ ํ–‰์˜ ๊ฐ’์„ ์ด์šฉํ•ด ๊ฐฑ์‹ ํ•˜์—ฌ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ์„ ์ตœ์†Œํ™”ํ–ˆ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ํ˜„์žฌ ๊ตฌํ˜„์ด ์ ์ ˆํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.

@parkhojeong parkhojeong left a comment

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.

์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค. ํ•ญ์ƒ ๊น”๋”ํ•œ ํ’€์ด ์˜ฌ๋ ค์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์‚ฌ์†Œํ•œ ์ปค๋ฉ˜ํŠธ ๋ช‡ ๊ฐœ ๋‚จ๊ฒผ์Šต๋‹ˆ๋‹ค.

int answer = 0;
int left = 0;

Set<Character> temp = new HashSet<>();

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.

์˜๋ฏธ๋ฅผ ๋“œ๋Ÿฌ๋‚ด๋Š” ๋„ค์ด๋ฐ ์‚ฌ์šฉํ•˜์‹œ๋ฉด ์ข‹์„ ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Comment on lines +16 to +19
while (temp.contains(s.charAt(right))) {
temp.remove(s.charAt(left));
left++;
}

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.

๊ฐ ๋ฌธ์ž์˜ ์ธ๋ฑ์Šค๋ฅผ ์ €์žฅํ•ด๋‘๋ฉด ์ค‘๋ณต ๋ฐœ์ƒ์‹œ ํ•œ ์นธ์”ฉ ์˜ฎ๊ธฐ์ง€ ์•Š์•„๋„ ๋˜์„œ ์ตœ์ ํ™”๊ฐ€ ๊ฐ€๋Šฅํ•  ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Comment on lines +3 to +15
// TC: O(m * n)
// SC: O(m * n)
class Solution {

private static int[] dx = {0, -1, 0, 1};
private static int[] dy = {1, 0, -1, 0};

private int n = 0;
private int m = 0;

public int numIslands(char[][] grid) {
n = grid[0].length;
m = grid.length;

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.

์‚ฌ์†Œํ•˜์ง€๋งŒ ๋ณต์žก๋„ ํ‘œ๊ธฐ๋Š” m * n ์ธ๋ฐ ๋ณ€์ˆ˜ ์ˆœ์„œ๋Š” n, m์ด๋ผ์„œ ์ˆœ์„œ๊ฐ€ ์™œ ๋ฐ”๋€Œ์–ด์žˆ์ง€ ์ƒ๊ฐ์ด ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. for loop์—์„œ๋„ m๋ถ€ํ„ฐ ๋‚˜์™€์„œ m, n ์ˆœ์„œ๋กœ ์„ ์–ธ๋˜๋ฉด ์ข€ ๋” ์ž์—ฐ์Šค๋Ÿฌ์šธ ๊ฑฐ ๊ฐ™์€๋ฐ n, m ์ˆœ์„œ๋กœ ์“ฐ์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”?

n = grid[0].length;
m = grid.length;

boolean[][] visited = new boolean[m][n];

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.

in-place ๋งˆํ‚นํ•˜๋Š” ๋ฐฉ์‹๋„ ๊ณ ๋ คํ•˜์…จ์„ ๊ฑฐ ๊ฐ™์€๋ฐ ํ˜น์‹œ ์ด ๋ฌธ์ œ์—์„œ visited ๋ฅผ ์‚ฌ์šฉํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants