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

[pull] master from youngyangyang04:master #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 4 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion problems/0300.最长上升子序列.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class Solution:
if len(nums) <= 1:
return len(nums)
dp = [1] * len(nums)
result = 0
result = 1
for i in range(1, len(nums)):
for j in range(0, i):
if nums[i] > nums[j]:
Expand Down
42 changes: 42 additions & 0 deletions problems/0669.修剪二叉搜索树.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ public:

## Java

**递归**

```Java
class Solution {
public TreeNode trimBST(TreeNode root, int low, int high) {
Expand All @@ -269,6 +271,46 @@ class Solution {

```

**迭代**

```Java
class Solution {
//iteration
public TreeNode trimBST(TreeNode root, int low, int high) {
if(root == null)
return null;
while(root != null && (root.val < low || root.val > high)){
if(root.val < low)
root = root.right;
else
root = root.left;
}

TreeNode curr = root;

//deal with root's left sub-tree, and deal with the value smaller than low.
while(curr != null){
while(curr.left != null && curr.left.val < low){
curr.left = curr.left.right;
}
curr = curr.left;
}
//go back to root;
curr = root;

//deal with root's righg sub-tree, and deal with the value bigger than high.
while(curr != null){
while(curr.right != null && curr.right.val > high){
curr.right = curr.right.left;
}
curr = curr.right;
}
return root;
}
}

````

## Python

递归法(版本一)
Expand Down

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