Skip to content

Commit 1146960

Browse files
committed
Fixed review warnings.
1 parent 34c3862 commit 1146960

File tree

10 files changed

+42
-42
lines changed

10 files changed

+42
-42
lines changed

src/main/java/g0201_0300/s0224_basic_calculator/Solution.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package g0201_0300.s0224_basic_calculator;
22

33
public class Solution {
4-
int i = 0;
4+
private int i = 0;
55

66
public int calculate(String s) {
77
char[] ca = s.toCharArray();
8-
98
return helper(ca);
109
}
1110

12-
public int helper(char[] ca) {
13-
11+
private int helper(char[] ca) {
1412
int num = 0;
1513
int prenum = 0;
1614
boolean isPlus = true;

src/main/java/g0201_0300/s0225_implement_stack_using_queues/MyStack.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44
import java.util.Queue;
55

66
public class MyStack {
7-
Queue<Integer> queueOne;
8-
Queue<Integer> queueTwo;
9-
int top;
7+
private Queue<Integer> queueOne;
8+
private Queue<Integer> queueTwo;
9+
private int top;
1010

11-
/** Initialize your data structure here. */
11+
// Initialize your data structure here.
1212
public MyStack() {
1313
queueOne = new LinkedList<>();
1414
queueTwo = new LinkedList<>();
1515
top = 0;
1616
}
1717

18-
/** Push element x onto stack. */
18+
// Push element x onto stack.
1919
public void push(int x) {
2020
queueOne.add(x);
2121
top = x;
2222
}
2323

24-
/** Removes the element on top of the stack and returns that element. */
24+
// Removes the element on top of the stack and returns that element.
2525
public int pop() {
2626
while (queueOne.size() > 1) {
2727
int val = queueOne.remove();
@@ -32,16 +32,15 @@ public int pop() {
3232
int popValue = queueOne.remove();
3333
queueOne.addAll(queueTwo);
3434
queueTwo.clear();
35-
3635
return popValue;
3736
}
3837

39-
/** Get the top element. */
38+
// Get the top element.
4039
public int top() {
4140
return top;
4241
}
4342

44-
/** Returns whether the stack is empty. */
43+
// Returns whether the stack is empty.
4544
public boolean empty() {
4645
return queueOne.isEmpty();
4746
}

src/main/java/g0201_0300/s0225_implement_stack_using_queues/readme.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ Implement the `MyStack` class:
2222

2323
**Output:** \[null, null, null, 2, 2, false\]
2424

25-
**Explanation:** MyStack myStack = new MyStack(); myStack.push(1); myStack.push(2); myStack.top(); // return 2 myStack.pop(); // return 2 myStack.empty(); // return False
25+
**Explanation:**
26+
27+
MyStack myStack = new MyStack();
28+
myStack.push(1);
29+
myStack.push(2);
30+
myStack.top(); // return 2
31+
myStack.pop(); // return 2
32+
myStack.empty(); // return False
2633

2734
**Constraints:**
2835

src/main/java/g0201_0300/s0228_summary_ranges/Solution.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ public List<String> summaryRanges(int[] nums) {
99
if (nums.length == 0) {
1010
return ranges;
1111
}
12-
int n = nums.length; // size of array
13-
int a = nums[0]; // start of range
14-
int b = a; // end of range
15-
12+
// size of array
13+
int n = nums.length;
14+
// start of range
15+
int a = nums[0];
16+
// end of range
17+
int b = a;
1618
StringBuilder strB = new StringBuilder();
1719
for (int i = 1; i < n; i++) {
1820
// we need to make a decision if the next element
@@ -26,19 +28,18 @@ public List<String> summaryRanges(int[] nums) {
2628
if (a != b) {
2729
strB.append("->").append(b);
2830
}
29-
3031
ranges.add(strB.toString());
3132
// since nums[i] is not accounted for by our range a->b
3233
// because nums[i] is not b+1, we need to set a and b
3334
// to this new range start point of bigger than b+1
3435
// maybe it is b+2? b+3? b+4? all we know is it is not b+1
3536
a = nums[i];
3637
b = a;
37-
3838
// Reset string builder
3939
strB.setLength(0);
4040
} else {
41-
b++; // if the next element expands our range we do so
41+
// if the next element expands our range we do so
42+
b++;
4243
}
4344
}
4445
// the only range that is not accounted for at this point is the last range
@@ -48,7 +49,6 @@ public List<String> summaryRanges(int[] nums) {
4849
strB.append("->").append(b);
4950
}
5051
ranges.add(strB.toString());
51-
5252
return ranges;
5353
}
5454
}

src/main/java/g0201_0300/s0232_implement_queue_using_stacks/MyQueue.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,39 @@
44
import java.util.Deque;
55

66
public class MyQueue {
7-
Deque<Integer> left;
8-
Deque<Integer> right;
9-
/** Initialize your data structure here. */
7+
private Deque<Integer> left;
8+
private Deque<Integer> right;
9+
// Initialize your data structure here.
1010
public MyQueue() {
1111
left = new ArrayDeque<>();
1212
right = new ArrayDeque<>();
1313
}
1414

15-
/** Push element x to the back of queue. */
15+
// Push element x to the back of queue.
1616
public void push(int x) {
1717
while (!right.isEmpty()) {
1818
left.add(right.pop());
1919
}
2020
left.add(x);
2121
}
2222

23-
/** Removes the element from in front of queue and returns that element. */
23+
// Removes the element from in front of queue and returns that element.
2424
public int pop() {
2525
while (!left.isEmpty()) {
2626
right.add(left.pop());
2727
}
2828
return right.pop();
2929
}
3030

31-
/** Get the front element. */
31+
// Get the front element.
3232
public int peek() {
3333
while (!left.isEmpty()) {
3434
right.add(left.pop());
3535
}
3636
return right.peek();
3737
}
3838

39-
/** Returns whether the queue is empty. */
39+
// Returns whether the queue is empty.
4040
public boolean empty() {
4141
return right.isEmpty() && left.isEmpty();
4242
}

src/main/java/g0201_0300/s0232_implement_queue_using_stacks/readme.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ Implement the `MyQueue` class:
2222

2323
**Output:** \[null, null, null, 1, 1, false\]
2424

25-
**Explanation:** MyQueue myQueue = new MyQueue(); myQueue.push(1); // queue is: \[1\] myQueue.push(2); // queue is: \[1, 2\] (leftmost is front of the queue) myQueue.peek(); // return 1 myQueue.pop(); // return 1, queue is \[2\] myQueue.empty(); // return false
25+
**Explanation:**
26+
27+
MyQueue myQueue = new MyQueue();
28+
myQueue.push(1); // queue is: [1]
29+
myQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)
30+
myQueue.peek(); // return 1
31+
myQueue.pop(); // return 1, queue is [2]
32+
myQueue.empty(); // return false
2633

2734
**Constraints:**
2835

src/test/java/g0201_0300/s0225_implement_stack_using_queues/MyStackTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ public void stackUsingQueue() {
1111
MyStack stack = new MyStack();
1212
stack.push(1);
1313
stack.push(2);
14-
assertThat(stack.top, equalTo(2));
15-
14+
assertThat(stack.top(), equalTo(2));
1615
assertThat(stack.pop(), equalTo(2));
17-
1816
assertThat(stack.empty(), equalTo(false));
1917
}
2018
}

src/test/java/g0201_0300/s0226_invert_binary_tree/SolutionTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,17 @@ public void invertTree() {
1212
TreeNode leftBottomLeft = new TreeNode(1);
1313
TreeNode leftBottomRight = new TreeNode(3);
1414
TreeNode left = new TreeNode(2, leftBottomLeft, leftBottomRight);
15-
1615
TreeNode rightBottomLeft = new TreeNode(6);
1716
TreeNode rightBottomRight = new TreeNode(9);
1817
TreeNode right = new TreeNode(7, rightBottomLeft, rightBottomRight);
19-
2018
TreeNode root = new TreeNode(4, left, right);
21-
2219
TreeNode leftBottomLeftInverted = new TreeNode(9);
2320
TreeNode leftBottomRightInverted = new TreeNode(6);
2421
TreeNode leftInverted = new TreeNode(7, leftBottomLeftInverted, leftBottomRightInverted);
25-
2622
TreeNode rightBottomLeftInverted = new TreeNode(3);
2723
TreeNode rightBottomRightInverted = new TreeNode(1);
2824
TreeNode rightInverted = new TreeNode(2, rightBottomLeftInverted, rightBottomRightInverted);
29-
3025
TreeNode rootInverted = new TreeNode(4, leftInverted, rightInverted);
31-
3226
assertThat(new Solution().invertTree(root).toString(), equalTo(rootInverted.toString()));
3327
}
3428
}

src/test/java/g0201_0300/s0230_kth_smallest_element_in_a_bst/SolutionTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ public class SolutionTest {
1212
public void kthSmallest() {
1313
TreeNode rightBottomLeft = new TreeNode(2);
1414
TreeNode left = new TreeNode(1, null, rightBottomLeft);
15-
1615
TreeNode right = new TreeNode(4);
1716
TreeNode root = new TreeNode(3, left, right);
18-
1917
assertThat(new Solution().kthSmallest(root, 1), equalTo(1));
2018
}
2119
}

src/test/java/g0201_0300/s0232_implement_queue_using_stacks/MyQueueTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public void queueUsingStacks() {
1111
MyQueue myQueue = new MyQueue();
1212
myQueue.push(1);
1313
myQueue.push(2);
14-
1514
assertThat(myQueue.peek(), equalTo(1));
1615
assertThat(myQueue.pop(), equalTo(1));
1716
assertThat(myQueue.empty(), equalTo(false));

0 commit comments

Comments
 (0)