Skip to content

Commit 6b6ad14

Browse files
committed
format
1 parent 760a511 commit 6b6ad14

File tree

4 files changed

+24
-44
lines changed

4 files changed

+24
-44
lines changed

src/main/java/g0001_0100/s0049_group_anagrams/Solution.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
// #Big_O_Time_O(n*k_log_k)_Space_O(n) #2024_11_11_Time_6_ms_(97.61%)_Space_47.7_MB_(69.56%)
66

77
import java.util.ArrayList;
8-
import java.util.Arrays;
98
import java.util.HashMap;
109
import java.util.List;
1110
import java.util.Map;
1211

1312
public class Solution {
1413
public List<List<String>> groupAnagrams(String[] strs) {
15-
Map<String, List<String>> anagrams= new HashMap<>();
16-
for (String word: strs) {
14+
Map<String, List<String>> anagrams = new HashMap<>();
15+
for (String word : strs) {
1716
char[] freq = new char[26];
1817
for (char c : word.toCharArray()) {
19-
freq[c - 'a'] ++;
18+
freq[c - 'a']++;
2019
}
2120
String keyString = new String(freq);
2221
if (!anagrams.containsKey(keyString)) {

src/main/java/g0001_0100/s0051_n_queens/Solution.java

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,36 @@
44
// #2024_11_11_Time_1_ms_(99.77%)_Space_44.8_MB_(61.16%)
55

66
import java.util.ArrayList;
7-
import java.util.Arrays;
87
import java.util.List;
98

109
public class Solution {
11-
public static List < List < String >> solveNQueens(int n) {
10+
public static List<List<String>> solveNQueens(int n) {
1211
char[][] board = new char[n][n];
13-
for (int i = 0; i < n; i++)
14-
for (int j = 0; j < n; j++)
15-
board[i][j] = '.';
16-
List < List < String >> res = new ArrayList < List < String >> ();
12+
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) board[i][j] = '.';
13+
List<List<String>> res = new ArrayList<List<String>>();
1714
int leftRow[] = new int[n];
1815
int upperDiagonal[] = new int[2 * n - 1];
1916
int lowerDiagonal[] = new int[2 * n - 1];
2017
solve(0, board, res, leftRow, lowerDiagonal, upperDiagonal);
2118
return res;
2219
}
2320

24-
25-
26-
static void solve(int col, char[][] board, List < List < String >> res, int leftRow[], int lowerDiagonal[], int upperDiagonal[]) {
21+
void solve(
22+
int col,
23+
char[][] board,
24+
List<List<String>> res,
25+
int leftRow[],
26+
int lowerDiagonal[],
27+
int upperDiagonal[]) {
2728
if (col == board.length) {
2829
res.add(construct(board));
2930
return;
3031
}
3132

3233
for (int row = 0; row < board.length; row++) {
33-
if (leftRow[row] == 0 && lowerDiagonal[row + col] == 0 && upperDiagonal[board.length - 1 + col - row] == 0) {
34+
if (leftRow[row] == 0
35+
&& lowerDiagonal[row + col] == 0
36+
&& upperDiagonal[board.length - 1 + col - row] == 0) {
3437
board[row][col] = 'Q';
3538
leftRow[row] = 1;
3639
lowerDiagonal[row + col] = 1;
@@ -44,27 +47,12 @@ static void solve(int col, char[][] board, List < List < String >> res, int left
4447
}
4548
}
4649

47-
48-
static List < String > construct(char[][] board) {
49-
List < String > res = new LinkedList < String > ();
50+
List<String> construct(char[][] board) {
51+
List<String> res = new LinkedList<String>();
5052
for (int i = 0; i < board.length; i++) {
5153
String s = new String(board[i]);
5254
res.add(s);
5355
}
5456
return res;
5557
}
56-
public static void main(String args[]) {
57-
int N = 4;
58-
List < List < String >> queen = solveNQueens(N);
59-
int i = 1;
60-
for (List < String > it: queen) {
61-
System.out.println("Arrangement " + i);
62-
for (String s: it) {
63-
System.out.println(s);
64-
}
65-
System.out.println();
66-
i += 1;
67-
}
68-
69-
}
7058
}

src/main/java/g0001_0100/s0055_jump_game/Solution.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@
66

77
public class Solution {
88
public boolean canJump(int[] nums) {
9-
if(nums.length == 1){
9+
if (nums.length == 1) {
1010
return true;
1111
}
12-
13-
if(nums[0] == 0){
12+
if (nums[0] == 0) {
1413
return false;
1514
}
16-
17-
int fin = nums.length-1; //3
18-
for(int i=nums.length-2;i>=0;i--){
19-
if((nums[i]+i) >= fin){
15+
int fin = nums.length - 1; // 3
16+
for (int i = nums.length - 2; i >= 0; i--) {
17+
if ((nums[i] + i) >= fin) {
2018
fin = i;
2119
}
2220
}

src/main/java/g0001_0100/s0079_word_search/Solution.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
public class Solution {
88
public boolean exists = false;
9+
910
public boolean exist(char[][] board, String word) {
1011
for (int i = 0; i < board.length; i++) {
1112
for (int j = 0; j < board[0].length; j++) {
@@ -14,7 +15,6 @@ public boolean exist(char[][] board, String word) {
1415
}
1516
}
1617
}
17-
1818
return exists;
1919
}
2020

@@ -23,31 +23,26 @@ private void dfs(char[][] board, String word, int wordIndex, int i, int j) {
2323
exists = true;
2424
return;
2525
}
26-
2726
char currentChar = board[i][j];
2827
char nextChar = word.charAt(wordIndex);
29-
3028
if (i > 0 && board[i - 1][j] == nextChar) {
3129
// go up
3230
board[i][j] = '-';
3331
dfs(board, word, wordIndex + 1, i - 1, j);
3432
board[i][j] = currentChar;
3533
}
36-
3734
if (j > 0 && board[i][j - 1] == nextChar) {
3835
// go left
3936
board[i][j] = '-';
4037
dfs(board, word, wordIndex + 1, i, j - 1);
4138
board[i][j] = currentChar;
4239
}
43-
4440
if (i < board.length - 1 && board[i + 1][j] == nextChar) {
4541
// go down
4642
board[i][j] = '-';
4743
dfs(board, word, wordIndex + 1, i + 1, j);
4844
board[i][j] = currentChar;
4945
}
50-
5146
if (j < board[0].length - 1 && board[i][j + 1] == nextChar) {
5247
// go right
5348
board[i][j] = '-';

0 commit comments

Comments
 (0)