File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -576,6 +576,38 @@ impl Solution {
576
576
}
577
577
```
578
578
579
+ 迭代
580
+
581
+ ``` rust
582
+ impl Solution {
583
+ pub fn get_minimum_difference (mut root : Option <Rc <RefCell <TreeNode >>>) -> i32 {
584
+ if root . is_none () {
585
+ return 0 ;
586
+ }
587
+ let mut stack = vec! [];
588
+ let mut pre = - 1 ;
589
+ let mut res = i32 :: MAX ;
590
+ while root . is_some () || ! stack . is_empty () {
591
+ while let Some (node ) = root {
592
+ root = node . borrow (). left. clone ();
593
+ stack . push (node );
594
+ }
595
+
596
+ let node = stack . pop (). unwrap ();
597
+
598
+ if pre >= 0 {
599
+ res = res . min (node . borrow (). val - pre );
600
+ }
601
+
602
+ pre = node . borrow (). val;
603
+
604
+ root = node . borrow (). right. clone ();
605
+ }
606
+ res
607
+ }
608
+ }
609
+ ```
610
+
579
611
<p align =" center " >
580
612
<a href =" https://programmercarl.com/other/kstar.html " target =" _blank " >
581
613
<img src =" ../pics/网站星球宣传海报.jpg " width =" 1000 " />
You can’t perform that action at this time.
0 commit comments