Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions longest-substring-without-repeating-characters/njngwn.java
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

문제를 안 읽었지만 요구하는 게 뭔지 알 거 같네요! 주석의 설명이 짧지만 명확하고 코드 역시 깔끔해서 가독성이 좋다고 생각합니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

감사합니다!!!

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Time Complexity: O(n), n: s.length()
// Space Complexity: O(n), n: s.length()
class Solution {
public int lengthOfLongestSubstring(String s) {
int begin = 0;
int end = 0;
int maxLength = 0;

Set<Character> letterSet = new HashSet<>();
while (end < s.length()) {
// if the letter is not in the hashset, then add it into hashset and move end pointer
if (!letterSet.contains(s.charAt(end))) {
letterSet.add(s.charAt(end));
++end;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제가 문제를 안 읽어서 잘은 모르겠는데 보통 후위 표기를 쓰는 걸 봤어서 전위 표기를 하신 이유가 궁금합니다~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아, 그냥 제 코딩습관인데 ++i가 i++보다 조금 더 빠르다는 말을 들어서요..!! 근데 자바라서 상관없을 것 같기도 하고, 요즘 컴파일러는 상관없다구 하네요. https://ssocoit.tistory.com/51

maxLength = Math.max(maxLength, end - begin); // update maxlength
} else { // if the letter is in the hashset, then remove it and move begin pointer
letterSet.remove(s.charAt(begin));
++begin;
}
}

return maxLength;
}
}
30 changes: 30 additions & 0 deletions number-of-islands/njngwn.java
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗! DFS로 푸는 문제들이 나왔군요. 좀 더 시간을 들여서 저도 풀었다면 좋았을텐데... 쪼끔 아쉬운 마음이 남네요.
고생하셨습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

꼼꼼하게 봐주셔서 감사해요!! 다음 기수에 한 번 더 도전하셔서 풀어보셔도 좋을 것 같아요!!

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Time Complexity: O(m*n), m: number of row, n: number of column
// Space Complexity: O(m*n), m: number of row, n: number of column, because of call stack
class Solution {
void findLand(char[][] grid, int row, int col) {
if (row < 0 || row > grid.length-1 || col < 0 || col > grid[0].length-1) return;
if (grid[row][col] == '0') return;

grid[row][col] = '0'; // make element '0'(water)

findLand(grid, row-1, col);
findLand(grid, row+1, col);
findLand(grid, row, col-1);
findLand(grid, row, col+1);
}

public int numIslands(char[][] grid) {
int num = 0;

for (int i = 0; i < grid.length; ++i) {
for (int j = 0; j < grid[0].length; ++j) {
if (grid[i][j] == '1') {
findLand(grid, i, j);
num++;
}
}
}

return num;
}
}
28 changes: 28 additions & 0 deletions set-matrix-zeroes/njngwn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Time Complexity: O(m*n)
// Space Complexity: O(m+n)
class Solution {
public void setZeroes(int[][] matrix) {
ArrayList<Integer> rowList = new ArrayList<>();
ArrayList<Integer> colList = new ArrayList<>();

for (int m = 0; m < matrix.length; ++m) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서도 전위 표기를 하셨네요! 선택한 이유가 있으신지 궁금합니다~

for (int n = 0; n < matrix[0].length; ++n) {
if (matrix[m][n] != 0) continue;
if (!rowList.contains(m)) rowList.add(m);
if (!colList.contains(n)) colList.add(n);
}
}

for (Integer row : rowList) {
for (int n = 0; n < matrix[0].length; ++n) {
matrix[row][n] = 0;
}
}

for (Integer col : colList) {
for (int n = 0; n < matrix.length; ++n) {
matrix[n][col] = 0;
}
}
}
}
19 changes: 19 additions & 0 deletions unique-paths/njngwn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Time Complexity: O(m*n), m: number of row, n: number of column
// Space Complexity: O(m*n), m: number of row, n: number of column
class Solution {
public int uniquePaths(int m, int n) {
int[][] pathMap = new int[m][n];

for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
if (i == 0 || j == 0) {
pathMap[i][j] = 1;
} else {
pathMap[i][j] = pathMap[i-1][j] + pathMap[i][j-1];
}
}
}

return pathMap[m-1][n-1];
}
}