Skip to content

Commit 73149d1

Browse files
committed
fd
1 parent 75dad34 commit 73149d1

File tree

4 files changed

+5
-42
lines changed

4 files changed

+5
-42
lines changed

solution/src/main/java/com/inuker/solution/FlattenBinaryTreeToLinkedList.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,14 @@ public TreeNode helper(TreeNode root) {
4444
if (root == null) {
4545
return null;
4646
}
47-
if (root.left == null && root.right == null) {
48-
return root;
49-
}
50-
5147
TreeNode right = root.right;
5248
TreeNode leftTail = null, rightTail = null;
5349

5450
if (root.left != null) {
5551
leftTail = helper(root.left);
5652
root.right = root.left;
57-
leftTail.right = right;
5853
root.left = null;
54+
leftTail.right = right;
5955
}
6056

6157
rightTail = helper(right);

solution/src/main/java/com/inuker/solution/RandomizedSet.java renamed to solution/src/main/java/com/inuker/solution/InsertDeleteGetRandom.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
* remove时要判断删除的是不是最后一个,另外交换了结尾后要更新结尾数的idx
1515
*/
1616
// 耗时111ms
17-
public class RandomizedSet {
17+
public class InsertDeleteGetRandom {
1818

1919
private HashMap<Integer, Integer> mMap;
2020
private List<Integer> mList;
2121
private Random mRandom;
2222

23-
public RandomizedSet() {
23+
public InsertDeleteGetRandom() {
2424
mList = new ArrayList<Integer>();
2525
mMap = new HashMap<Integer, Integer>();
2626
mRandom = new Random();

solution/src/main/java/com/inuker/solution/RandomizedCollection.java renamed to solution/src/main/java/com/inuker/solution/InsertDeleteGetRandomII.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
/**
1515
* 这题的区别在于允许数字重复,那么保存index需要用set,删除的时候从set中随便删一个就行了
1616
*/
17-
public class RandomizedCollection {
17+
public class InsertDeleteGetRandomII {
1818

1919
private HashMap<Integer, HashSet<Integer>> map;
2020
private List<Integer> list = new ArrayList<Integer>();
2121
private Random random;
2222

2323
/** Initialize your data structure here. */
24-
public RandomizedCollection () {
24+
public InsertDeleteGetRandomII() {
2525
map = new HashMap<Integer, HashSet<Integer>>();
2626
list = new Vector<Integer>();
2727
random = new Random();

test/src/main/java/com/inuker/test/Test2.java

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,5 @@
2121
*/
2222

2323
public class Test2 {
24-
/**
25-
* TestCase
26-
* [3,1,1], 3
27-
*/
28-
public int search(int[] nums, int target) {
29-
int left = 0, right = nums.length - 1;
30-
31-
while (left <= right) {
32-
int mid = (left + right) / 2;
33-
34-
if (target == nums[mid]) {
35-
return mid;
36-
}
37-
38-
if (nums[mid] > nums[left]) {
39-
if (target >= nums[left] && target < nums[mid]) {
40-
right = mid - 1;
41-
} else {
42-
left = mid + 1;
43-
}
44-
} else if (nums[mid] == nums[left]) {
45-
left++;
46-
} else {
47-
if (target > nums[mid] && target <= nums[right]) {
48-
left = mid + 1;
49-
} else {
50-
right = mid - 1;
51-
}
52-
}
53-
}
54-
55-
return -1;
56-
}
5724

5825
}

0 commit comments

Comments
 (0)