8000 clean up · lvelve0901/Leetcode-1@017d79f · GitHub
[go: up one dir, main page]

Skip to content

Commit 017d79f

Browse files
clean up
1 parent 76f2d48 commit 017d79f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+694
-421
lines changed

README.md

Lines changed: 29 additions & 25 deletions
Large diffs are not rendered by default.

src/main/java/com/stevesun/solutions/ContiguousArray.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import java.util.Map;
55

66
/**
7+
* 525. Contiguous Array
8+
*
79
* Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1.
810
911
Example 1:

src/main/java/com/stevesun/solutions/CountPrime.java

Lines changed: 0 additions & 97 deletions
This file was deleted.

src/main/java/com/stevesun/solutions/FirstUniqueCharacterinaString.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/main/java/com/stevesun/solutions/InorderSuccessorInBST.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/main/java/com/stevesun/solutions/LargestBSTSubtree.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/main/java/com/stevesun/solutions/MSOnlineAssessment.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import java.util.*;
44

55
public class MSOnlineAssessment {
6+
/**Given an array, return the start/end indices of the contiguous subarray that have the largest sum.
7+
8+
Note:
9+
1. There could be multiple subarrays, return all of the indices.*/
610

711
public static void main(String... args) {
812
int[] nums = new int[]{1,2,3,4,5, -1, -3, -6, 3, 2, -4};

src/main/java/com/stevesun/solutions/MedianofTwoSortedArrays.java

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/main/java/com/stevesun/solutions/SymmetricTree.java renamed to src/main/java/com/stevesun/solutions/_101.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Given a binary tree, check whether it is a mirror of itself (ie, symmetric aroun
2424
2525
Note:
2626
Bonus points if you could solve it both recursively and iteratively. */
27-
public class SymmetricTree {
27+
public class _101 {
2828
//a very natural idea flows out using recursion. Cheers.
2929
public boolean isSymmetric(TreeNode root) {
3030
if(root == null) return true;
@@ -38,7 +38,7 @@ private boolean isSymmetric(TreeNode left, TreeNode right) {
3838
}
3939

4040
public static void main(String... strings) {
41-
SymmetricTree test = new SymmetricTree();
41+
_101 test = new _101();
4242
TreeNode root = new TreeNode(1);
4343
System.out.println(test.isSymmetric(root));
4444
}

src/main/java/com/stevesun/solutions/_105.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@ public class _105 {
1414
//credit: https://discuss.leetcode.com/topic/29838/5ms-java-clean-solution-with-caching
1515
//use HashMap as the cache so that accessing inorder index becomes O(1) time
1616
public TreeNode buildTree(int[] preorder, int[] inorder) {
17-
Map<Integer, Integer> inMap = new HashMap();
17+
Map<Integer, Integer> inorderMap = new HashMap();
1818
for (int i = 0; i < inorder.length; i++) {
19-
inMap.put(inorder[i], i);
19+
inorderMap.put(inorder[i], i);
2020
}
2121

22-
return buildTree(preorder, 0, preorder.length-1, 0, inorder.length-1, inMap);
22+
return buildTree(preorder, 0, preorder.length-1, 0, inorder.length-1, inorderMap);
2323
}
2424

25-
private TreeNode buildTree(int[] preorder, int preStart, int preEnd, int inStart, int inEnd, Map<Integer, Integer> inMap) {
25+
private TreeNode buildTree(int[] preorder, int preStart, int preEnd, int inStart, int inEnd, Map<Integer, Integer> inorderMap) {
2626
if (preStart > preEnd || inStart > inEnd) return null;
2727

2828
TreeNode root = new TreeNode(preorder[preStart]);
29-
int inRoot = inMap.get(root.val);
29+
int inRoot = inorderMap.get(root.val);
3030
int numsLeft = inRoot - inStart;
3131

32-
root.left = buildTree(preorder, preStart+1, preStart+numsLeft, inStart, inRoot-1, inMap);
33-
root.right = buildTree(preorder, preStart+numsLeft+1, preEnd, inRoot+1, inEnd, inMap);
32+
root.left = buildTree(preorder, preStart+1, preStart+numsLeft, inStart, inRoot-1, inorderMap);
33+
root.right = buildTree(preorder, preStart+numsLeft+1, preEnd, inRoot+1, inEnd, inorderMap);
3434
return root;
3535
}
3636

0 commit comments

Comments
 (0)
0