From bb8e7312b64b13f98ca6c6ae88260a4f57375acd Mon Sep 17 00:00:00 2001 From: Lozakaka <102352821+lozakaka@users.noreply.github.com> Date: 2023年4月25日 03:25:45 -0400 Subject: [PATCH 1/3] =?UTF-8?q?Update=200098.=E9=AA=8C=E8=AF=81=E4=BA=8C?= =?UTF-8?q?=E5=8F=89=E6=90=9C=E7=B4=A2=E6=A0=91.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增java 統一迭代法的寫法 有通過. AC --- ...11346円220円234円347円264円242円346円240円221円.md" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git "a/problems/0098.351円252円214円350円257円201円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" "b/problems/0098.351円252円214円350円257円201円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" index 95afe6805c..ccb6330558 100644 --- "a/problems/0098.351円252円214円350円257円201円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" +++ "b/problems/0098.351円252円214円350円257円201円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" @@ -259,6 +259,36 @@ public: ## Java +```Java +//使用統一迭代法 +class Solution { + public boolean isValidBST(TreeNode root) { + Stack
stack = new Stack(); + TreeNode pre = null; + if(root != null) + stack.add(root); + while(!stack.isEmpty()){ + TreeNode curr = stack.peek(); + if(curr != null){ + stack.pop(); + if(curr.right != null) + stack.add(curr.right); + stack.add(curr); + stack.add(null); + if(curr.left != null) + stack.add(curr.left); + }else{ + stack.pop(); + TreeNode temp = stack.pop(); + if(pre != null && pre.val>= temp.val) + return false; + pre = temp; + } + } + return true; + } +} +``` ```Java class Solution { // 递归 From 75c7f940d112893dd6a1f89f844b710a87b202e1 Mon Sep 17 00:00:00 2001 From: Lozakaka <102352821+lozakaka@users.noreply.github.com> Date: 2023年4月25日 04:03:17 -0400 Subject: [PATCH 2/3] =?UTF-8?q?=E6=96=B0=E5=A2=9Ejava=20=E7=B5=B1=E4=B8=80?= =?UTF-8?q?=E8=BF=AD=E4=BB=A3=E6=B3=95-=E4=B8=AD=E5=BA=8F=E9=81=8D?= =?UTF-8?q?=E5=8E=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增java 統一迭代法-中序遍历 --- ...17347円273円235円345円257円271円345円267円256円.md" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git "a/problems/0530.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円347円232円204円346円234円200円345円260円217円347円273円235円345円257円271円345円267円256円.md" "b/problems/0530.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円347円232円204円346円234円200円345円260円217円347円273円235円345円257円271円345円267円256円.md" index fa1430dec1..cd24c6faf1 100644 --- "a/problems/0530.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円347円232円204円346円234円200円345円260円217円347円273円235円345円257円271円345円267円256円.md" +++ "b/problems/0530.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円347円232円204円346円234円200円345円260円217円347円273円235円345円257円271円345円267円256円.md" @@ -174,6 +174,39 @@ class Solution { } } ``` +統一迭代法-中序遍历 +```Java +class Solution { + public int getMinimumDifference(TreeNode root) { + Stack
stack = new Stack(); + TreeNode pre = null; + int result = Integer.MAX_VALUE; + + if(root != null) + stack.add(root); + while(!stack.isEmpty()){ + TreeNode curr = stack.peek(); + if(curr != null){ + stack.pop(); + if(curr.right != null) + stack.add(curr.right); + stack.add(curr); + stack.add(null); + if(curr.left != null) + stack.add(curr.left); + }else{ + stack.pop(); + TreeNode temp = stack.pop(); + if(pre != null) + result = Math.min(result, temp.val - pre.val); + pre = temp; + } + } + return result; + } +} +``` + 迭代法-中序遍历 ```java From 42cdaa2e9a2639dab6931a5733aabf6ed92df62a Mon Sep 17 00:00:00 2001 From: blockChain-Fans <33158355+1055373165@users.noreply.github.com> Date: 2023年4月27日 23:34:50 +0800 Subject: [PATCH 3/3] =?UTF-8?q?Update=200035.=E6=90=9C=E7=B4=A2=E6=8F=92?= =?UTF-8?q?=E5=85=A5=E4=BD=8D=E7=BD=AE.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 返回值应该是 right+1 把 --- ...264円242円346円217円222円345円205円245円344円275円215円347円275円256円.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/problems/0035.346円220円234円347円264円242円346円217円222円345円205円245円344円275円215円347円275円256円.md" "b/problems/0035.346円220円234円347円264円242円346円217円222円345円205円245円344円275円215円347円275円256円.md" index 58340c21a1..efc875777b 100644 --- "a/problems/0035.346円220円234円347円264円242円346円217円222円345円205円245円344円275円215円347円275円256円.md" +++ "b/problems/0035.346円220円234円347円264円242円346円217円222円345円205円245円344円275円215円347円275円256円.md" @@ -274,7 +274,7 @@ func searchInsert(nums []int, target int) int { left = mid + 1 } } - return len(nums) + return right+1 } ```

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