Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 94b7cbc

Browse files
add 1861
1 parent 91ba4b8 commit 94b7cbc

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1861|[Rotating the Box](https://leetcode.com/problems/rotating-the-box/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1861.java) ||Medium|Array, Two Pointers|
1112
|1860|[Incremental Memory Leak](https://leetcode.com/problems/incremental-memory-leak/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1860.java) ||Medium|Math|
1213
|1859|[Sorting the Sentence](https://leetcode.com/problems/sorting-the-sentence/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1859.java) ||Easy|String, Sort|
1314
|1854|[Maximum Population Year](https://leetcode.com/problems/maximum-population-year/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1854.java) ||Easy|Array|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1861 {
4+
public static class Solution1 {
5+
public char[][] rotateTheBox(char[][] box) {
6+
int m = box.length;
7+
int n = box[0].length;
8+
for (int i = 0; i < m; i++) {
9+
for (int j = n - 1; j >= 0; j--) {
10+
if (box[i][j] == '#') {
11+
int empty = j + 1;
12+
while (empty < n && box[i][empty] == '.') {
13+
empty++;
14+
}
15+
if (empty < n && box[i][empty] == '.') {
16+
box[i][empty] = '#';
17+
box[i][j] = '.';
18+
} else if (empty - 1 < n && box[i][empty - 1] == '.') {
19+
box[i][empty - 1] = '#';
20+
box[i][j] = '.';
21+
}
22+
23+
}
24+
}
25+
}
26+
char[][] result = new char[n][m];
27+
int k = m - 1;
28+
for (int i = 0; i < m; i++) {
29+
for (int j = 0; j < n; j++) {
30+
result[j][k] = box[i][j];
31+
}
32+
k--;
33+
}
34+
return result;
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)