Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 95f6a10

Browse files
added binary tree programs
1 parent 43b1a52 commit 95f6a10

File tree

5 files changed

+94
-0
lines changed

5 files changed

+94
-0
lines changed

‎DSA_College/Trees/BinaryTree.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ public void preOrder(TreeNode root) {
2626
}
2727
}
2828
}
29+
30+
// inOrder using Recursion
31+
public void inOrder(TreeNode root) {
32+
589
33+
}
2934
}

‎Leetcode/Leetcode_46.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package Leetcode;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class Leetcode_46 {
7+
public List<List<Integer>> permute(int[] nums) {
8+
List<List<Integer>> rs = new ArrayList<>();
9+
if (nums.length < 1)
10+
return rs;
11+
helper(rs, new ArrayList<>(), nums, new boolean[nums.length]);
12+
return rs;
13+
}
14+
15+
public void helper(List<List<Integer>> rs, List<Integer> arr, int[] nums, boolean[] visited) {
16+
if (arr.size() == nums.length) {
17+
rs.add(new ArrayList<>(arr));
18+
return;
19+
}
20+
for (int i = 0;i < nums.length;i++) {
21+
if (visited[i])
22+
continue;
23+
arr.add(nums[i]);
24+
visited[i] = true;
25+
helper(rs, arr, nums, visited);
26+
arr.remove(arr.size() - 1);
27+
visited[i] = false;
28+
}
29+
}
30+
}

‎Leetcode/Leetcode_47.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package Leetcode;
2+
3+
public class Leetcode_47 {
4+
}

‎Leetcode/Leetcode_63.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package Leetcode;
2+
3+
public class Leetcode_63 {
4+
public static int uniquePathsWithObstacles(int[][] ar) {
5+
if (ar[0][0] == 1)
6+
return 0;
7+
int row = ar.length;
8+
int col = ar[0].length;
9+
for (int i = 0;i < row;i++) {
10+
for (int j = 0;j < col;j++) {
11+
if (i == 0 || j == 0 && ar[i][j] != 1) {
12+
if (ar[i][j] == 1 || (i != 0 && ar[i - 1][0] == 0) || (j != 0 && ar[i][j - 1] == 0)) {
13+
ar[i][j] = 0;
14+
} else {
15+
ar[i][j] = 1;
16+
}
17+
} else {
18+
if (ar[i][j] == 1) {
19+
ar[i][j] = 0;
20+
} else {
21+
ar[i][j] = ar[i - 1][j] + ar[i][j - 1];
22+
}
23+
}
24+
}
25+
}
26+
return ar[row][col];
27+
}
28+
29+
public static void main(String[] args) {
30+
System.out.println(uniquePathsWithObstacles(new int[]{}));
31+
}
32+
}

‎Leetcode/Leetcode_64.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package Leetcode;
2+
3+
public class Leetcode_64 {
4+
public int minPathSum(int[][] grid) {
5+
if (grid == null || grid.length == 0 || grid[0].length == 0)
6+
return 0;
7+
int row = grid.length, col = grid[0].length;
8+
int[][] dp = new int[row][col];
9+
dp[0][0] = grid[0][0];
10+
for (int i = 1; i < row; i++) {
11+
dp[i][0] = dp[i - 1][0] + grid[i][0];
12+
}
13+
for (int i = 1; i < col; i++) {
14+
dp[0][i] = dp[0][i - 1] + grid[0][i];
15+
}
16+
17+
for (int i = 0; i < row; i++) {
18+
for (int j = 0; j < col; j++) {
19+
dp[i][j] = Math.min()
20+
}
21+
}
22+
}
23+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /