Skip to content

Commit ea1019d

Browse files
committed
fd
1 parent 9cbb23e commit ea1019d

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

leetcode/solution/src/BSTIterator.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ public class BSTIterator {
66
private TreeNode mCurNode;
77

88
public BSTIterator(TreeNode root) {
9-
mStack = new Stack<TreeNode>();
9+
mStack = new Stack<>();
1010
mCurNode = root;
11-
12-
// for (mCurNode = root; mCurNode != null; mCurNode = mCurNode.left) {
13-
// mStack.push(mCurNode);
14-
// }
1511
}
1612

1713
/**
@@ -41,19 +37,4 @@ public int next() {
4137

4238
return result;
4339
}
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-
}*/
5940
}

leetcode/src/Main.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
public class Main {
44

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+
524
public static void main(String[] args) {
625
}
726
}

0 commit comments

Comments
 (0)