File tree Expand file tree Collapse file tree 3 files changed +70
-28
lines changed Expand file tree Collapse file tree 3 files changed +70
-28
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public boolean isPowerOfTwo (int n ) {
3
+ if (n % 2 != 0 && n != 1 ) {
4
+ return false ;
5
+ }
6
+ int start = 0 ;
7
+ int end = n / 2 ;
8
+ while (start <= end ) {
9
+ int mid = (start + end ) / 2 ;
10
+ int pow = (int ) (Math .pow (2 , mid ));
11
+ if (n == pow ) {
12
+ return true ;
13
+ }
14
+ else if (n > pow ) {
15
+ start = mid + 1 ;
16
+ }
17
+ else {
18
+ end = mid - 1 ;
19
+ }
20
+ }
21
+ return false ;
22
+ }
23
+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ class BrowserHistory {
2
+
3
+ Node root ;
4
+ public BrowserHistory (String homepage ) {
5
+ root = new Node (homepage );
6
+ }
7
+
8
+ public void visit (String url ) {
9
+ Node node = new Node (url );
10
+ root .next = null ;
11
+ root .next = node ;
12
+ node .prev = root ;
13
+ root = root .next ;
14
+ }
15
+
16
+ public String back (int steps ) {
17
+ while (steps -- > 0 && root .prev != null ) {
18
+ root = root .prev ;
19
+ }
20
+ return root .val ;
21
+ }
22
+
23
+ public String forward (int steps ) {
24
+ while (steps -- > 0 && root .next != null ) {
25
+ root = root .next ;
26
+ }
27
+ return root .val ;
28
+ }
29
+ }
30
+
31
+ class Node {
32
+ String val ;
33
+ Node next ;
34
+ Node prev ;
35
+
36
+ public Node (String val ) {
37
+ this .val = val ;
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Your BrowserHistory object will be instantiated and called as such:
43
+ * BrowserHistory obj = new BrowserHistory(homepage);
44
+ * obj.visit(url);
45
+ * String param_2 = obj.back(steps);
46
+ * String param_3 = obj.forward(steps);
47
+ */
You can’t perform that action at this time.
0 commit comments