Skip to content

Commit

Permalink
update 424 java, 417 java, progress
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Mar 13, 2024
1 parent f17cb61 commit deeb3d7
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 64 deletions.
2 changes: 1 addition & 1 deletion data/progress.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
20240313: 338,347,371
20240313: 338,347,371,417(again),424(again)
20240312: 297(again),300,322(again),323
20240311: 261(again!!!),268,269(again),271,295(again)
20240310: 213,217,226,230,235,238,242,252,253
Expand Down
18 changes: 9 additions & 9 deletions data/to_review.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
2024-05-07 -> ['338,347,371']
2024-05-07 -> ['338,347,371,417(again),424(again)']
2024-05-06 -> ['297(again),300,322(again),323']
2024-05-05 -> ['261(again!!!),268,269(again),271,295(again)']
2024-05-04 -> ['213,217,226,230,235,238,242,252,253']
Expand All @@ -12,7 +12,7 @@
2024-04-24 -> ['39,48(again),49,53,54']
2024-04-23 -> ['20,21,23,33(again)']
2024-04-22 -> ['1,3,5,4,19']
2024-04-16 -> ['338,347,371']
2024-04-16 -> ['338,347,371,417(again),424(again)']
2024-04-15 -> ['297(again),300,322(again),323']
2024-04-14 -> ['261(again!!!),268,269(again),271,295(again)']
2024-04-13 -> ['213,217,226,230,235,238,242,252,253']
Expand All @@ -23,27 +23,27 @@
2024-04-08 -> ['100,102,104,105(again)']
2024-04-07 -> ['73,76,79(again),91,25']
2024-04-06 -> ['55(again),56,62,70']
2024-04-03 -> ['338,347,371', '39,48(again),49,53,54']
2024-04-03 -> ['338,347,371,417(again),424(again)', '39,48(again),49,53,54']
2024-04-02 -> ['297(again),300,322(again),323', '20,21,23,33(again)']
2024-04-01 -> ['261(again!!!),268,269(again),271,295(again)', '1,3,5,4,19']
2024-03-31 -> ['213,217,226,230,235,238,242,252,253']
2024-03-30 -> ['207(again!!!),208,211(again),212']
2024-03-29 -> ['152,153(again),190,191,198,200,206(again)']
2024-03-28 -> ['139(again),141,143(again)']
2024-03-27 -> ['121,124(again),125,128,133(again)']
2024-03-26 -> ['338,347,371', '100,102,104,105(again)']
2024-03-26 -> ['338,347,371,417(again),424(again)', '100,102,104,105(again)']
2024-03-25 -> ['297(again),300,322(again),323', '73,76,79(again),91,25']
2024-03-24 -> ['261(again!!!),268,269(again),271,295(again)', '55(again),56,62,70']
2024-03-23 -> ['213,217,226,230,235,238,242,252,253']
2024-03-22 -> ['207(again!!!),208,211(again),212']
2024-03-21 -> ['338,347,371', '152,153(again),190,191,198,200,206(again)', '39,48(again),49,53,54']
2024-03-21 -> ['338,347,371,417(again),424(again)', '152,153(again),190,191,198,200,206(again)', '39,48(again),49,53,54']
2024-03-20 -> ['297(again),300,322(again),323', '139(again),141,143(again)', '20,21,23,33(again)']
2024-03-19 -> ['261(again!!!),268,269(again),271,295(again)', '121,124(again),125,128,133(again)', '1,3,5,4,19']
2024-03-18 -> ['338,347,371', '213,217,226,230,235,238,242,252,253', '100,102,104,105(again)']
2024-03-18 -> ['338,347,371,417(again),424(again)', '213,217,226,230,235,238,242,252,253', '100,102,104,105(again)']
2024-03-17 -> ['297(again),300,322(again),323', '207(again!!!),208,211(again),212', '73,76,79(again),91,25']
2024-03-16 -> ['338,347,371', '261(again!!!),268,269(again),271,295(again)', '152,153(again),190,191,198,200,206(again)', '55(again),56,62,70']
2024-03-15 -> ['338,347,371', '297(again),300,322(again),323', '213,217,226,230,235,238,242,252,253', '139(again),141,143(again)']
2024-03-14 -> ['338,347,371', '297(again),300,322(again),323', '261(again!!!),268,269(again),271,295(again)', '207(again!!!),208,211(again),212', '121,124(again),125,128,133(again)']
2024-03-16 -> ['338,347,371,417(again),424(again)', '261(again!!!),268,269(again),271,295(again)', '152,153(again),190,191,198,200,206(again)', '55(again),56,62,70']
2024-03-15 -> ['338,347,371,417(again),424(again)', '297(again),300,322(again),323', '213,217,226,230,235,238,242,252,253', '139(again),141,143(again)']
2024-03-14 -> ['338,347,371,417(again),424(again)', '297(again),300,322(again),323', '261(again!!!),268,269(again),271,295(again)', '207(again!!!),208,211(again),212', '121,124(again),125,128,133(again)']
2024-03-13 -> ['297(again),300,322(again),323', '261(again!!!),268,269(again),271,295(again)', '213,217,226,230,235,238,242,252,253', '152,153(again),190,191,198,200,206(again)', '100,102,104,105(again)', '39,48(again),49,53,54']
2024-03-12 -> ['261(again!!!),268,269(again),271,295(again)', '213,217,226,230,235,238,242,252,253', '207(again!!!),208,211(again),212', '139(again),141,143(again)', '73,76,79(again),91,25', '20,21,23,33(again)']
2024-03-11 -> ['213,217,226,230,235,238,242,252,253', '207(again!!!),208,211(again),212', '152,153(again),190,191,198,200,206(again)', '121,124(again),125,128,133(again)', '55(again),56,62,70', '1,3,5,4,19']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,57 @@

public class PacificAtlanticWaterFlow {

// TODO : fix below
// List<List<Integer>> res = new ArrayList<>();
// //boolean[][] seen;
//
// // V0
// public List<List<Integer>> pacificAtlantic(int[][] heights) {
// V0
// IDEA : DFS
// private static final int[][] DIRECTIONS_ = new int[][]{{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
// private int numRows_;
// private int numCols_;
// private int[][] landHeights_;
//
// // double check ??
// if (heights.length == 1 && heights[0].length == 1) {
// List<Integer> _ans = new ArrayList<>();
// _ans.add(0);
// _ans.add(0);
// this.res.add(_ans);
// return this.res;
// public List<List<Integer>> pacificAtlantic(int[][] matrix) {
// if (matrix.length == 0 || matrix[0].length == 0) {
// return new ArrayList<>();
// }
//
// int len = heights.length;
// int width = heights[0].length;
// numRows_ = matrix.length;
// numCols_ = matrix[0].length;
// landHeights_ = matrix;
// boolean[][] pacificReachable = new boolean[numRows_][numCols_];
// boolean[][] atlanticReachable = new boolean[numRows_][numCols_];
//
// for (int x = 0; x < width; x++) {
// for (int y = 0; y < len; y++) {
//
// boolean[][] seen = new boolean[len][width];
// String status = _help(heights, x, y, 0, 0, seen, null);
// System.out.println(">>> status = " + status + " (x,y) = " + x + ", " + y);
// for (int i = 0; i < numRows_; i++) {
// dfs_(i, 0, pacificReachable);
// dfs_(i, numCols_ - 1, atlanticReachable);
// }
// for (int i = 0; i < numCols_; i++) {
// dfs_(0, i, pacificReachable);
// dfs_(numRows_ - 1, i, atlanticReachable);
// }
//
// if (status != null && status.contains("a") && status.contains("p")) {
// List<Integer> _cur = new ArrayList<>();
// _cur.add(x);
// _cur.add(y);
// this.res.add(_cur);
// List<List<Integer>> commonCells = new ArrayList<>();
// for (int i = 0; i < numRows_; i++) {
// for (int j = 0; j < numCols_; j++) {
// if (pacificReachable[i][j] && atlanticReachable[i][j]) {
// List<Integer> cell = new ArrayList<>();
// cell.add(i);
// cell.add(j);
// commonCells.add(cell);
// }
// }
// }
//
// return this.res;
// return commonCells;
// }
//
// private String _help(int[][] heights, int x, int y, int lastX, int lastY, boolean[][] seen, String status) {
//
// int len = heights.length;
// int width = heights[0].length;
//
// if (y == 0 || x == 0){
// status += "-p";
// }
//
// if (y == len-1 || x == width-1){
// status += "-a";
// }
//
// seen[y][x] = true;
//
// if (x >= width || x < 0 || y >= len || y < 0 || seen[y][x] == true || heights[lastY][lastX] < heights[y][x]) {
// return status;
// private void dfs_(int row, int col, boolean[][] reachable) {
// reachable[row][col] = true;
// for (int[] dir : DIRECTIONS_) {
// int newRow = row + dir[0];
// int newCol = col + dir[1];
// if (newRow < 0 || newRow >= numRows_ || newCol < 0 || newCol >= numCols_ || reachable[newRow][newCol] || landHeights[newRow][newCol] < landHeights[row][col]) {
// continue;
// }
// dfs(newRow, newCol, reachable);
// }
//
// return _help(heights, x+1, y, x, y, seen, status) +
// _help(heights, x-1, y, x, y, seen, status)+
// _help(heights, x, y+1, x, y, seen, status)+
// _help(heights, x, y-1, x, y, seen, status);
// }

// V1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,34 @@
from collections import Counter
class Solution(object):
def characterReplacement(self, s, k):
"""
NOTE !!!
table record frequent of element met in while loop
"""
table = Counter()
res = 0
"""
Define 2 pointers
p1 : left pointer
p2 : right pointer
"""
p1 = p2 = 0
# below can be either while or for loop
while p2 < len(s):
table[s[p2]] += 1
p2 += 1
"""
### NOTE : if remain elements > k, means there is no possibility to make this substring as "longest substring containing the same letter"
-> remain elements = p1 - p2 - max(table.values())
-> e.g. if we consider "max(table.values()" as the "repeating character", then "p2 - p1 - max(table.values()" is the count of elements we need to replace
-> so we need to clear "current candidate" for next iteration
### NOTE : if remain different elements > k, means there is no possibility to make this substring as "longest substring containing the same letter"
-> remain different elements = p1 - p2 - max(table.values())
-> e.g. if we consider "max(table.values()" as the "repeating character", then "p2 - p1 - max(table.values()" is the count of different elements we need to replace
-> we also need to clear "current candidate" for next iteration (while move left pointer)
e.g.
table[s[p1]] -= 1
p1 += 1
"""
while p2 - p1 - max(table.values()) > k:
table[s[p1]] -= 1
Expand Down

0 comments on commit deeb3d7

Please sign in to comment.