From bfc4b777c2844c3cb0fc24b899ed013264b94469 Mon Sep 17 00:00:00 2001 From: SinnoLn Date: Thu, 10 Sep 2026 22:36:34 +0900 Subject: [PATCH] 1861. Rotating the Box --- .../1861. Rotating the Box.java" | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 "leetcode3/\354\235\264\354\247\204\355\235\254/1861. Rotating the Box.java" diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/1861. Rotating the Box.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/1861. Rotating the Box.java" new file mode 100644 index 00000000..a9720b0f --- /dev/null +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/1861. Rotating the Box.java" @@ -0,0 +1,70 @@ +/* +1. 아이디어: 중력 적용 문제 + 원래 배열에서 장애물을 만나기 전까지 '#'의 수를 계산 후, 장에물 위치-1 인덱스부터 '#'개수 만큼 채워준다. + 이후, 90도 회전 공식을 적용한다. + +2. 시간복잡도: O(M) + O(M*N) + O(M*N) => O(M*N) + +3. 자료구조/알고리즘: 구현 + +*/ + +class Solution { + private int n,m; + public char[][] rotateTheBox(char[][] boxGrid) { + // 90도 회전시 중력 작용 + // 고정물 존재 + // 최대 500*500 + // 무조건 우측으로 + + m = boxGrid.length; + n = boxGrid[0].length; + + char[][] tmp = new char[m][n]; + + for(int i=0; i0) { + tmp[i][idx] = '#'; + cnt--; + idx--; + } + } + + } + + int idx = n-1; + while(cnt>0) { + tmp[i][idx] = '#'; + idx--; + cnt--; + } + } + + return rotate90(tmp); + } + + private char[][] rotate90 (char[][] tmp) { + + char ans[][] = new char[n][m]; + for(int i=0; i