FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

0202_Week09(Java) by Luren3 · Pull Request #1101 · algorithm007-class02/algorithm007-class02 · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .iml  (1) .java  (33) .xml  (6) No extension  (2) dotfile  (6) All 5 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Binary file added .DS_Store
Binary file not shown.
19 changes: 19 additions & 0 deletions .idea/$CACHE_FILE$

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/algorithm007-class02.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions .idea/checkstyle-idea.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

116 changes: 116 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/dictionaries

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Week_01/.DS_Store
Binary file not shown.
Binary file added Week_03/.DS_Store
Binary file not shown.
Binary file added Week_04/.DS_Store
Binary file not shown.
Binary file added Week_06/.DS_Store
Binary file not shown.
16 changes: 16 additions & 0 deletions Week_06/G20200343040202/LeetCode_221_0202.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public int maximalSquare(char[][] matrix) {
int rows = matrix.length, cols = rows > 0 ? matrix[0].length : 0;
int[][] dp = new int[rows + 1][cols + 1];
int maxsqlen = 0;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= cols; j++) {
if (matrix[i-1][j-1] == '1'){
dp[i][j] = Math.min(Math.min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;
maxsqlen = Math.max(maxsqlen, dp[i][j]);
}
}
}
return maxsqlen * maxsqlen;
}
}
56 changes: 56 additions & 0 deletions Week_06/G20200343040202/LeetCode_621_0202.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class Solution {
public int[][] imageSmoother(int[][] M) {
int r = M.length;
int c = M[0].length;
int[][] res = new int[r][c];
for(int i = 0; i < r;i++){
for(int j = 0;j < c;j++){
res[i][j] = add(M,i,j,r,c);
}
}
return res;
}

private int add(int[][] M,int i,int j,int m ,int n){
int res = 0;
int num = 0;
if(i-1>=0){
res += M[i-1][j];
num++;
}
if(i+1 < m){
res += M[i+1][j];
num++;
}
if(j-1 >= 0){
res += M[i][j-1];
num++;
}
if(j+1 < n){
res += M[i][j+1];
num++;
}

if(i+1 < m &&j-1 >=0){
res += M[i+1][j-1];
num++;
}
if(i-1>=0&&j-1>=0){
res += M[i-1][j-1];
num++;
}
if(i-1>=0&&j+1<n){
res += M[i-1][j+1];
num++;
}

if(j+1 < n && i+1 < m){
res += M[i+1][j+1];
num++;
}
res += M[i][j];
num++;
res /=num;
return res;
}
}
15 changes: 15 additions & 0 deletions Week_06/G20200343040202/LeetCode_647_0202.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
public int countSubstrings(String s) {
int res = 0;
boolean dp[][] = new boolean[s.length()][s.length()];
for (int j = 0; j < s.length(); j++) {
for (int i = j; i >= 0; i--) {
if (s.charAt(i) == s.charAt(j) && ((j - i < 2) || dp[i + 1][j - 1])) {
dp[i][j] = true;
res++;
}
}
}
return res;
}
}
20 changes: 20 additions & 0 deletions Week_06/G20200343040202/LeetCode_64_0202.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Solution {
public int minPathSum(int[][] grid) {

int dp[][] = new int[grid.length][grid[0].length];
dp[0][0] = grid[0][0];

for (int i = 1; i < grid.length; i++) {
dp[i][0] = grid[i][0] + dp[i - 1][0];
}
for (int i = 1; i < grid[0].length; i++) {
dp[0][i] = grid[0][i] + dp[0][i - 1];
}
for (int i = 1; i < grid.length; i++) {
for (int j = 1; j < grid[0].length; j++) {
dp[i][j] = Math.min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];
}
}
return dp[grid.length - 1][grid[0].length - 1];
}
}
49 changes: 49 additions & 0 deletions Week_06/G20200343040202/LeetCode_76_0202.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class Solution {
public String minWindow(String s, String t) {
if (s == null || s == "" || t == null || t == "" || s.length() < t.length()) {
return "";
}

int[] needs = new int[128];
int[] window = new int[128];

for (int i = 0; i < t.length(); i++) {
needs[t.charAt(i)]++;
}

int left = 0;
int right = 0;

String res = "";

int count = 0;

int minLength = s.length() + 1;

while (right < s.length()) {
char ch = s.charAt(right);
window[ch]++;
if (needs[ch] > 0 && needs[ch] >= window[ch]) {
count++;
}

while (count == t.length()) {
ch = s.charAt(left);
if (needs[ch] > 0 && needs[ch] >= window[ch]) {
count--;
}
if (right - left + 1 < minLength) {
minLength = right - left + 1;
res = s.substring(left, right + 1);

}
window[ch]--;
left++;

}
right++;

}
return res;
}
}
Loading

Back | FazBrowse Home | New Git URL