File tree Expand file tree Collapse file tree 2 files changed +20
-20
lines changed Expand file tree Collapse file tree 2 files changed +20
-20
lines changed Original file line number Diff line number Diff line change @@ -6,12 +6,8 @@ public class BSTIterator {
6
6
private TreeNode mCurNode ;
7
7
8
8
public BSTIterator (TreeNode root ) {
9
- mStack = new Stack <TreeNode >();
9
+ mStack = new Stack <>();
10
10
mCurNode = root ;
11
-
12
- // for (mCurNode = root; mCurNode != null; mCurNode = mCurNode.left) {
13
- // mStack.push(mCurNode);
14
- // }
15
11
}
16
12
17
13
/**
@@ -41,19 +37,4 @@ public int next() {
41
37
42
38
return result ;
43
39
}
44
-
45
- /** 这样写也好,不过要注意在构造函数中初始化如上注释部分
46
- public int next() {
47
- if (mCurNode == null) {
48
- mCurNode = mStack.pop();
49
- }
50
-
51
- int val = mCurNode.val;
52
-
53
- for (mCurNode = mCurNode.right; mCurNode != null; mCurNode = mCurNode.left) {
54
- mStack.push(mCurNode);
55
- }
56
-
57
- return val;
58
- }*/
59
40
}
Original file line number Diff line number Diff line change 2
2
3
3
public class Main {
4
4
5
+ public double myPow (double x , int n ) {
6
+ return myPow (x , n );
7
+ }
8
+
9
+ private double myPow (double x , long n ) {
10
+ if (n == 0 ) {
11
+ return 1 ;
12
+ }
13
+ if (n < 0 ) {
14
+ return myPow (1 / x , -n );
15
+ }
16
+ double res = myPow (x , n / 2 );
17
+ if (n % 2 != 0 ) {
18
+ return res * res * x ;
19
+ } else {
20
+ return res * res ;
21
+ }
22
+ }
23
+
5
24
public static void main (String [] args ) {
6
25
}
7
26
}
You can’t perform that action at this time.
0 commit comments