From ace8eca8379025f0b6838e4e0855c21f98f41810 Mon Sep 17 00:00:00 2001 From: SinnoLn Date: Tue, 3 Nov 2026 22:45:11 +0900 Subject: [PATCH 01/14] 1914. Cyclically Rotating a Grid --- .../1914. Cyclically Rotating a Grid.java" | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 "leetcode3/\354\235\264\354\247\204\355\235\254/1914. Cyclically Rotating a Grid.java" diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/1914. Cyclically Rotating a Grid.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/1914. Cyclically Rotating a Grid.java" new file mode 100644 index 00000000..63a24f35 --- /dev/null +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/1914. Cyclically Rotating a Grid.java" @@ -0,0 +1,70 @@ +/* + +1. 아이디어 : 방문 배열과 이동 방향을 미리 정의 후, i,i부터 아래 -> 오른쪽 -> 위 -> 왼쪽 경로의 원소 위치 수집 + k번 만큼 회전(이동)한 위치에 넣는다 - 모듈러 연산 필요 + + +2. 시간복잡도 : O(2*N*M) + +3. 자료구조/알고리즘 : 방향 전환, 배열 + + */ + +class Solution { + private boolean[][] visited; + private int[][] ans; + private int[] dy = {0,1,0,-1}; + private int[] dx = {-1,0,1,0}; + public int[][] rotateGrid(int[][] grid, int k) { + // m, n은 짝수 + // k 횟수 만큼 왼쪽 회전 + + visited = new boolean[grid.length][grid[0].length]; + ans = new int[grid.length][grid[0].length]; + int limit = Math.min(grid.length, grid[0].length)/2; + for(int i=0; i list = new ArrayList<>(); + visited[y][x] = true; + list.add(new int[]{y,x}); + + int startY = y; + int startX = x; + + // 아래 방향 + int dir = 1; + while(true) { + int ny = y+dy[dir]; + int nx = x+dx[dir]; + + if(ny == startY && nx == startX) break; + + if(ny<0 || nx<0 || ny>=grid.length || nx>=grid[0].length || visited[ny][nx]) { + dir=(dir+1)%4; + continue; + } + + y = ny; + x = nx; + + visited[y][x] = true; + list.add(new int[]{y,x}); + } + + int size = list.size(); + int move = k%size; + + for(int i=0; i Date: Tue, 3 Nov 2026 22:50:37 +0900 Subject: [PATCH 02/14] Create 1861. Rotating the Box.py --- .../1861. Rotating the Box.py" | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/1861. Rotating the Box.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1861. Rotating the Box.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1861. Rotating the Box.py" new file mode 100644 index 00000000..3cb39f32 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1861. Rotating the Box.py" @@ -0,0 +1,61 @@ +# + +''' +1. 아이디어 : +- 돌을 오른쪽으로 미는 메서드 +오른쪽으로 밀때는 장애물을 만나기전까지 돌을 센 후, 장애물을 만나거나 끝까지 가면 다시 뒤로 가며 돌로 채운다. + +- 90도로 회전하는 메서드 + +2. 시간복잡도 : + O(n * m * m) + +3. 자료구조/알고리즘 : +- + +''' +class Solution: + def rotateTheBox(self, boxGrid: list[list[str]]) -> list[list[str]]: + n = len(boxGrid) + m = len(boxGrid[0]) + + def push_right(box): + for row in box: + stones = 0 + for i in range(m): + cell = row[i] + if cell == "#": + stones += 1 + row[i] = "." + elif cell == ".": + pass + elif cell == "*": + for j in range(i-1, i-1-stones,-1): + row[j] = "#" + stones = 0 + for i in range(m-1, m-1-stones, -1): + row[i] = "#" + return box + + boxGrid_push = push_right(boxGrid) + + + def rotate_90(box): + boxGrid90 = [[[""] for _ in range(n)] for _ in range(m)] + for i in range(n): + for j in range(m): + boxGrid90[j][n-i-1] = box[i][j] + return boxGrid90 + + return rotate_90(boxGrid_push) + + """ + [["#",".","*","."] + ["#","#","*","."]] + [ + [[''], ['']], + [[''], ['']], + [[''], ['']], + [[''], ['']] + ] + """ From 439b0fe6221f35b701bcbb721d229762aff081ac Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Tue, 3 Nov 2026 22:50:49 +0900 Subject: [PATCH 03/14] Create 1914. Cyclically Rotating a Grid.py --- .../1914. Cyclically Rotating a Grid.py" | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/1914. Cyclically Rotating a Grid.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/1914. Cyclically Rotating a Grid.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/1914. Cyclically Rotating a Grid.py" new file mode 100644 index 00000000..fd84c5d0 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/1914. Cyclically Rotating a Grid.py" @@ -0,0 +1,63 @@ +# + +''' +1. 아이디어 : +가장 바깥쪽 layer부터 [0,0], [1,1], ...[n,n]원소를 가장 처음으로 원을 그리며 숫자와 위치를 각 배열에 저장. +배열에 저장된 숫자의 offset을 계산해서 offset이 위치하는 곳부터 가장 처음 원을 시작한 곳부터 채운다. + +2. 시간복잡도 : + O( min(n, m)/2 * n * m * 2) + +3. 자료구조/알고리즘 : +- + +''' +class Solution: + def rotateGrid(self, grid: List[List[int]], k: int) -> List[List[int]]: + n = len(grid) + m = len(grid[0]) + max_layer = min(n//2, m//2) + layers = {} + + dx = [0,1,0,-1] + dy = [1,0,-1,0] + + for layer in range(max_layer): + pos =[] + nums = [] + + x, y = layer, layer + direction = 0 + + top = layer + left = layer + bottom = n - layer - 1 + right = m - layer - 1 + + length = 2 * (bottom - top + right - left) + + for _ in range(length): + pos.append((x, y)) + nums.append(grid[x][y]) + + nx = x + dx[direction] + ny = y + dy[direction] + + if not (top <= nx <= bottom and left <= ny <= right): + direction = (direction + 1 ) % 4 + nx = x + dx[direction] + ny = y + dy[direction] + + x, y = nx, ny + + offset = k % length + nums = nums[offset:] + nums[:offset] + + for i in range(len(pos)): + x, y = pos[i] + grid[x][y] = nums[i] + + return grid + + + From ca467cce24bb4c8add966d19af983953d393f3e9 Mon Sep 17 00:00:00 2001 From: rimogsu Date: Tue, 3 Nov 2026 22:51:30 +0900 Subject: [PATCH 04/14] 1914 --- .../v4/1914. Cyclically Rotating a Grid.py" | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 "leetcode3/\353\263\200\354\247\200\355\230\221/v4/1914. Cyclically Rotating a Grid.py" diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v4/1914. Cyclically Rotating a Grid.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v4/1914. Cyclically Rotating a Grid.py" new file mode 100644 index 00000000..d8066499 --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v4/1914. Cyclically Rotating a Grid.py" @@ -0,0 +1,63 @@ +''' +시간 초과 +''' +''' +0,0 -> 0,1 +0,1 -> 0,2 +... +0,4 -> 0,5 +0,5 -> 1,5 +1,5 -> 2,5 +2,5 -> 3,5 +3,5 -> 3,4 +''' +class Solution: + def rotate_one(self, grid: List[List[int]]) -> List[List[int]]: + xlen = len(grid[0]) + ylen = len(grid) + vertexs = [(0,0),(0,ylen-1),(xlen-1,ylen-1),(xlen-1,0)] + rotate_num = min(xlen,ylen) // 2 + tmp = [[0] * xlen for _ in range(ylen)] + + while rotate_num > 0: + # print(rotate_num) + # print(vertexs) + + for y in range(vertexs[0][1],vertexs[1][1]): + tmp[y+1][vertexs[0][0]] = grid[y][vertexs[0][0]] + + # print(tmp) + + for x in range(vertexs[1][0],vertexs[2][0]): + tmp[vertexs[1][1]][x+1] = grid[vertexs[1][1]][x] + + # print(tmp) + + for y in range(vertexs[2][1],vertexs[3][1],-1): + tmp[y-1][vertexs[2][0]] = grid[y][vertexs[2][0]] + + # print(tmp) + + for x in range(vertexs[3][0],vertexs[0][0],-1): + tmp[vertexs[3][1]][x-1] = grid[vertexs[3][1]][x] + + tmp2 = [ + (vertexs[0][0]+1,vertexs[0][1]+1), + (vertexs[1][0]+1,vertexs[1][1]-1), + (vertexs[2][0]-1,vertexs[2][1]-1), + (vertexs[3][0]-1,vertexs[3][1]+1) + ] + vertexs = tmp2 + rotate_num -= 1 + return tmp + + def rotateGrid(self, grid: List[List[int]], k: int) -> List[List[int]]: + tmp = grid + + xlen = len(grid[0]) + ylen = len(grid) + + while k > 0: + tmp = self.rotate_one(tmp) + k-=1 + return tmp \ No newline at end of file From eb98a7d6842717effd841bdad6e102addd62a94b Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Tue, 3 Nov 2026 23:13:19 +0900 Subject: [PATCH 05/14] Create copy --- .../\354\206\241\354\243\274\355\230\234/copy" | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 "leetcode3/\354\206\241\354\243\274\355\230\234/copy" diff --git "a/leetcode3/\354\206\241\354\243\274\355\230\234/copy" "b/leetcode3/\354\206\241\354\243\274\355\230\234/copy" new file mode 100644 index 00000000..917c84d4 --- /dev/null +++ "b/leetcode3/\354\206\241\354\243\274\355\230\234/copy" @@ -0,0 +1,13 @@ +# + +''' +1. 아이디어 : + + +2. 시간복잡도 : + O() + +3. 자료구조/알고리즘 : + + +''' From c812d880bcaf57041b2c4336bde2a89d9d3df18c Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Tue, 3 Nov 2026 23:13:47 +0900 Subject: [PATCH 06/14] Create copy --- .../\354\230\244\354\235\200\355\230\201/copy" | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 "leetcode3/\354\230\244\354\235\200\355\230\201/copy" diff --git "a/leetcode3/\354\230\244\354\235\200\355\230\201/copy" "b/leetcode3/\354\230\244\354\235\200\355\230\201/copy" new file mode 100644 index 00000000..917c84d4 --- /dev/null +++ "b/leetcode3/\354\230\244\354\235\200\355\230\201/copy" @@ -0,0 +1,13 @@ +# + +''' +1. 아이디어 : + + +2. 시간복잡도 : + O() + +3. 자료구조/알고리즘 : + + +''' From 27d04d402229e2ea7941582042d156e002ee4d60 Mon Sep 17 00:00:00 2001 From: oheunhyuck <71165142+oheunhyuck@users.noreply.github.com> Date: Tue, 3 Nov 2026 23:16:09 +0900 Subject: [PATCH 07/14] Create 1914. Cyclically Rotating a Grid --- .../1914. Cyclically Rotating a Grid" | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 "leetcode3/\354\230\244\354\235\200\355\230\201/1914. Cyclically Rotating a Grid" diff --git "a/leetcode3/\354\230\244\354\235\200\355\230\201/1914. Cyclically Rotating a Grid" "b/leetcode3/\354\230\244\354\235\200\355\230\201/1914. Cyclically Rotating a Grid" new file mode 100644 index 00000000..22c6a60d --- /dev/null +++ "b/leetcode3/\354\230\244\354\235\200\355\230\201/1914. Cyclically Rotating a Grid" @@ -0,0 +1,46 @@ +from collections import deque +class Solution: + def rotate(self,grid,x,y,xn,yn,k): + dq=deque([]) + cur_x=x + cur_y=y + while cur_x=x: + dq.append((cur_y,cur_x)) + cur_x-=1 + cur_x+=1 + cur_y-=1 + while cur_y>y: + dq.append((cur_y,cur_x)) + cur_y-=1 + return dq + temp=yn*xn-(yn-2)*(xn-2) + k=k%temp + + if k=yn and k List[List[int]]: + return self.rotate(grid,0,0,len(grid[0]),len(grid),k) From 7e871bf6ed18174b26bd4f55e4e4006434fe8045 Mon Sep 17 00:00:00 2001 From: oheunhyuck <71165142+oheunhyuck@users.noreply.github.com> Date: Tue, 3 Nov 2026 23:17:15 +0900 Subject: [PATCH 08/14] Create 1861. Rotating the Box --- .../1861. Rotating the Box" | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 "leetcode3/\354\230\244\354\235\200\355\230\201/1861. Rotating the Box" diff --git "a/leetcode3/\354\230\244\354\235\200\355\230\201/1861. Rotating the Box" "b/leetcode3/\354\230\244\354\235\200\355\230\201/1861. Rotating the Box" new file mode 100644 index 00000000..bd99fc3e --- /dev/null +++ "b/leetcode3/\354\230\244\354\235\200\355\230\201/1861. Rotating the Box" @@ -0,0 +1,11 @@ +class Solution: + def rotateTheBox(self, grid: list[list[str]]) -> list[list[str]]: + + + for y in range(len(grid)) + board=[[] for _ in range(len(grid[0]))] + for y in grid: + for i in range(len(y)): + board[i].append(y[i]) + + From a0912bdd83e0bdd79a61d84ef6b42ea1d86e807c Mon Sep 17 00:00:00 2001 From: zzu <90972641+Zuhye@users.noreply.github.com> Date: Tue, 3 Nov 2026 23:18:04 +0900 Subject: [PATCH 09/14] 1914. Cyclically Rotating a Grid Implement function to rotate a grid k times. --- .../1914. Cyclically Rotating a Grid" | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 "leetcode3/\354\206\241\354\243\274\355\230\234/1914. Cyclically Rotating a Grid" diff --git "a/leetcode3/\354\206\241\354\243\274\355\230\234/1914. Cyclically Rotating a Grid" "b/leetcode3/\354\206\241\354\243\274\355\230\234/1914. Cyclically Rotating a Grid" new file mode 100644 index 00000000..7b290f92 --- /dev/null +++ "b/leetcode3/\354\206\241\354\243\274\355\230\234/1914. Cyclically Rotating a Grid" @@ -0,0 +1,28 @@ +class Solution: + def rotateGrid(self, grid: List[List[int]], k: int) -> List[List[int]]: + m = len(grid) + n = len(grid[0]) + + minLen = min(m, n) + + for i in range(minLen //2): + for j in range(k): # k만큼 돌기 + tmp = grid[i][i] + + for k in range(i, n-1): # <- + grid[i][k] = grid[i][k+1] + for k in range(i, m-1): # ^ + grid[k][n-1] = grid[k+1][n-1] + for k in range(n-1, i, -1): # -> + grid[m-1][k] = grid[m-1][k-1] + for k in range(m-1, i, -1): + grid[k][i] = grid[k-1][i] + + grid[i+1][i] = tmp + + return grid + + +/** +수정해야함 +**/ From d9cd06f25a658d6287e55d6b24eb08fef566eaa6 Mon Sep 17 00:00:00 2001 From: oheunhyuck <71165142+oheunhyuck@users.noreply.github.com> Date: Wed, 4 Nov 2026 07:35:29 +0900 Subject: [PATCH 10/14] Create 442. Find All Duplicates in an Array --- .../442. Find All Duplicates in an Array" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "leetcode3/\354\230\244\354\235\200\355\230\201/442. Find All Duplicates in an Array" diff --git "a/leetcode3/\354\230\244\354\235\200\355\230\201/442. Find All Duplicates in an Array" "b/leetcode3/\354\230\244\354\235\200\355\230\201/442. Find All Duplicates in an Array" new file mode 100644 index 00000000..69fd4676 --- /dev/null +++ "b/leetcode3/\354\230\244\354\235\200\355\230\201/442. Find All Duplicates in an Array" @@ -0,0 +1,33 @@ +class Solution: + def c(self,nums,t): + + if isinstance(nums[t],int): + temp=nums[t] + nums[t]='1' + self.c(nums,temp-1) + elif nums[t]=='.': + nums[t]='1' + else: + nums[t]=str(int(nums[t])+1) + + def findDuplicates(self, nums: list[int]) -> list[int]: + ans=[] + for i in range(len(nums)): + if isinstance(nums[i],int): + if nums[i]==i+1: + nums[i]='1' + else: + temp=nums[i] + nums[i]='.' + self.c(nums,temp-1) + + + else:continue + + for i in range(len(nums)): + if nums[i]=='2': + ans.append(i+1) + return ans + + + From 40f2e2d476e09539e77320153bd062b70893bbc7 Mon Sep 17 00:00:00 2001 From: SinnoLn Date: Wed, 4 Nov 2026 13:45:35 +0900 Subject: [PATCH 11/14] 442. Find All Duplicates in an Array --- ...442. Find All Duplicates in an Array.java" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 "leetcode3/\354\235\264\354\247\204\355\235\254/442. Find All Duplicates in an Array.java" diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/442. Find All Duplicates in an Array.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/442. Find All Duplicates in an Array.java" new file mode 100644 index 00000000..c669ddb7 --- /dev/null +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/442. Find All Duplicates in an Array.java" @@ -0,0 +1,30 @@ +/* + +1. 아이디어 : 초반 SWAP으로 각 위치를 교환하려고 했으나 예외케이스가 늘어나 실패 + 추가 공간 복잡도를 활용할 수 없고 각 nums[i]의 범위가 1<=nums[i]<=n인것을 바탕으로 숫자를 만났을때 음수를 붙여 이미 본 적있는지 체크 + +2. 시간복잡도 : O(N) + +3. 자료구조/알고리즘 : 부호 반전 + + */ + +class Solution { + // 각 원소는 최대 두 번 등장 + // 시간복잡도 O(N) + // 추가 공간은 배열의 크기에 따라가 변하지 않고 고정적이어야 함 + // 답을 위한 추가 공간 제외 + // 두번 등장하는 모든 윈소를 출력 (출력 순서는 상관 없음) + public List findDuplicates(int[] nums) { + Listans = new ArrayList<>(); + + for(int i=0; i Date: Wed, 4 Nov 2026 14:37:28 +0000 Subject: [PATCH 12/14] Create 442. Find All Duplicates in an Array.py --- .../442. Find All Duplicates in an Array.py" | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 "leetcode3/\354\265\234\354\233\220\354\244\200/442. Find All Duplicates in an Array.py" diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/442. Find All Duplicates in an Array.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/442. Find All Duplicates in an Array.py" new file mode 100644 index 00000000..87317023 --- /dev/null +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/442. Find All Duplicates in an Array.py" @@ -0,0 +1,3 @@ +class Solution: + def findDuplicates(self, nums: list[int]) -> list[int]: + return [num for num, count in Counter(nums).items() if count == 2] From aea293218fc1329992b0a5295fd092361221dd8d Mon Sep 17 00:00:00 2001 From: Won Joon Thomas Choi <113500771+724thomas@users.noreply.github.com> Date: Wed, 4 Nov 2026 23:39:58 +0900 Subject: [PATCH 13/14] Update 442. Find All Duplicates in an Array.py --- .../442. Find All Duplicates in an Array.py" | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git "a/leetcode3/\354\265\234\354\233\220\354\244\200/442. Find All Duplicates in an Array.py" "b/leetcode3/\354\265\234\354\233\220\354\244\200/442. Find All Duplicates in an Array.py" index 87317023..d38e9d84 100644 --- "a/leetcode3/\354\265\234\354\233\220\354\244\200/442. Find All Duplicates in an Array.py" +++ "b/leetcode3/\354\265\234\354\233\220\354\244\200/442. Find All Duplicates in an Array.py" @@ -1,3 +1,19 @@ class Solution: def findDuplicates(self, nums: list[int]) -> list[int]: return [num for num, count in Counter(nums).items() if count == 2] + + + +class Solution: + def findDuplicates(self, nums: list[int]) -> list[int]: + result = [] + + for num in nums: + idx = abs(num) - 1 + + if nums[idx] < 0: + result.append(abs(num)) + else: + nums[idx] *= -1 + + return result From 77cdd9817c80a0207d2601f75f8b08b9d957cb5f Mon Sep 17 00:00:00 2001 From: zzu <90972641+Zuhye@users.noreply.github.com> Date: Wed, 4 Nov 2026 23:46:55 +0900 Subject: [PATCH 14/14] Implement findDuplicates function to identify duplicates --- .../442. Find All Duplicates in an Array" | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 "leetcode3/\354\206\241\354\243\274\355\230\234/442. Find All Duplicates in an Array" diff --git "a/leetcode3/\354\206\241\354\243\274\355\230\234/442. Find All Duplicates in an Array" "b/leetcode3/\354\206\241\354\243\274\355\230\234/442. Find All Duplicates in an Array" new file mode 100644 index 00000000..8b121e72 --- /dev/null +++ "b/leetcode3/\354\206\241\354\243\274\355\230\234/442. Find All Duplicates in an Array" @@ -0,0 +1,16 @@ +class Solution: + def findDuplicates(self, nums: list[int]) -> list[int]: + ans = [] + numbers = {} + + for i in nums: + if i in numbers: + numbers[i] += 1 + else: + numbers[i] = 1 + + for i in numbers: + if numbers[i] ==2: + ans.append(i) + + return ans