chore(java): format
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
c6dfb95ec0
commit
f0cdb67ac1
21 changed files with 520 additions and 532 deletions
|
@ -20,8 +20,13 @@ class TreeNode {
|
||||||
int val;
|
int val;
|
||||||
TreeNode left;
|
TreeNode left;
|
||||||
TreeNode right;
|
TreeNode right;
|
||||||
|
|
||||||
TreeNode() {}
|
TreeNode() {}
|
||||||
TreeNode(int val) { this.val = val; }
|
|
||||||
|
TreeNode(int val) {
|
||||||
|
this.val = val;
|
||||||
|
}
|
||||||
|
|
||||||
TreeNode(int val, TreeNode left, TreeNode right) {
|
TreeNode(int val, TreeNode left, TreeNode right) {
|
||||||
this.val = val;
|
this.val = val;
|
||||||
this.left = left;
|
this.left = left;
|
||||||
|
@ -31,7 +36,8 @@ class TreeNode {
|
||||||
|
|
||||||
class BSTIterator {
|
class BSTIterator {
|
||||||
private enum Position {
|
private enum Position {
|
||||||
Todo, Done
|
Todo,
|
||||||
|
Done
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Entry {
|
private class Entry {
|
||||||
|
@ -58,16 +64,15 @@ class BSTIterator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayDeque<Entry> stack = new ArrayDeque<>();
|
private ArrayDeque<Entry> stack = new ArrayDeque<>();
|
||||||
|
|
||||||
public BSTIterator(TreeNode root) {
|
public BSTIterator(TreeNode root) {
|
||||||
stack.addLast(new Entry(root, Position.Todo));
|
stack.addLast(new Entry(root, Position.Todo));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int next() {
|
public int next() {
|
||||||
for (
|
for (Entry last = stack.getLast();
|
||||||
Entry last = stack.getLast();
|
|
||||||
last != null && last.position == Position.Todo;
|
last != null && last.position == Position.Todo;
|
||||||
last = stack.getLast()
|
last = stack.getLast()) {
|
||||||
) {
|
|
||||||
stack.removeLast().expand(stack);
|
stack.removeLast().expand(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,8 +86,6 @@ class BSTIterator {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Your BSTIterator object will be instantiated and called as such:
|
* Your BSTIterator object will be instantiated and called as such: BSTIterator obj = new
|
||||||
* BSTIterator obj = new BSTIterator(root);
|
* BSTIterator(root); int param_1 = obj.next(); boolean param_2 = obj.hasNext();
|
||||||
* int param_1 = obj.next();
|
|
||||||
* boolean param_2 = obj.hasNext();
|
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,17 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* Definition for a binary tree node.
|
* Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode
|
||||||
* public class TreeNode {
|
* right; TreeNode() {} TreeNode(int val) { this.val = val; } TreeNode(int val, TreeNode left,
|
||||||
* int val;
|
* TreeNode right) { this.val = val; this.left = left; this.right = right; } }
|
||||||
* TreeNode left;
|
|
||||||
* TreeNode right;
|
|
||||||
* TreeNode() {}
|
|
||||||
* TreeNode(int val) { this.val = val; }
|
|
||||||
* TreeNode(int val, TreeNode left, TreeNode right) {
|
|
||||||
* this.val = val;
|
|
||||||
* this.left = left;
|
|
||||||
* this.right = right;
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
*/
|
*/
|
||||||
class Solution {
|
class Solution {
|
||||||
private TreeNode sortedArrayToBST(int[] nums, int min, int max) {
|
private TreeNode sortedArrayToBST(int[] nums, int min, int max) {
|
||||||
|
@ -21,10 +11,7 @@ class Solution {
|
||||||
|
|
||||||
int mid = (min + max) / 2;
|
int mid = (min + max) / 2;
|
||||||
return new TreeNode(
|
return new TreeNode(
|
||||||
nums[mid],
|
nums[mid], sortedArrayToBST(nums, min, mid - 1), sortedArrayToBST(nums, mid + 1, max));
|
||||||
sortedArrayToBST(nums, min, mid - 1),
|
|
||||||
sortedArrayToBST(nums, mid + 1, max)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TreeNode sortedArrayToBST(int[] nums) {
|
public TreeNode sortedArrayToBST(int[] nums) {
|
||||||
|
|
|
@ -7,9 +7,11 @@ import java.util.List;
|
||||||
interface NestedInteger {
|
interface NestedInteger {
|
||||||
// @return true if this NestedInteger holds a single integer, rather than a nested list.
|
// @return true if this NestedInteger holds a single integer, rather than a nested list.
|
||||||
public boolean isInteger();
|
public boolean isInteger();
|
||||||
|
|
||||||
// @return the single integer that this NestedInteger holds, if it holds a single integer
|
// @return the single integer that this NestedInteger holds, if it holds a single integer
|
||||||
// Return null if this NestedInteger holds a nested list
|
// Return null if this NestedInteger holds a nested list
|
||||||
public Integer getInteger();
|
public Integer getInteger();
|
||||||
|
|
||||||
// @return the nested list that this NestedInteger holds, if it holds a nested list
|
// @return the nested list that this NestedInteger holds, if it holds a nested list
|
||||||
// Return empty list if this NestedInteger holds a single integer
|
// Return empty list if this NestedInteger holds a single integer
|
||||||
public List<NestedInteger> getList();
|
public List<NestedInteger> getList();
|
||||||
|
@ -97,7 +99,6 @@ class NestedIterator implements Iterator<Integer> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Your NestedIterator object will be instantiated and called as such:
|
* Your NestedIterator object will be instantiated and called as such: NestedIterator i = new
|
||||||
* NestedIterator i = new NestedIterator(nestedList);
|
* NestedIterator(nestedList); while (i.hasNext()) v[f()] = i.next();
|
||||||
* while (i.hasNext()) v[f()] = i.next();
|
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -11,11 +11,9 @@ class Solution {
|
||||||
dp[0][0] = 1;
|
dp[0][0] = 1;
|
||||||
|
|
||||||
for (int toss = 1; toss <= n; ++toss) {
|
for (int toss = 1; toss <= n; ++toss) {
|
||||||
for (
|
for (int sumIdx = toss, maxSumIdx = Math.min(target, toss * k);
|
||||||
int sumIdx = toss, maxSumIdx = Math.min(target, toss * k);
|
|
||||||
sumIdx <= maxSumIdx;
|
sumIdx <= maxSumIdx;
|
||||||
++sumIdx
|
++sumIdx) {
|
||||||
) {
|
|
||||||
for (int f = 1; f <= Math.min(k, sumIdx); ++f) {
|
for (int f = 1; f <= Math.min(k, sumIdx); ++f) {
|
||||||
dp[toss][sumIdx] = (dp[toss][sumIdx] + dp[toss - 1][sumIdx - f]) % MOD;
|
dp[toss][sumIdx] = (dp[toss][sumIdx] + dp[toss - 1][sumIdx - f]) % MOD;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,6 @@ class RLEIterator {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Your RLEIterator object will be instantiated and called as such:
|
* Your RLEIterator object will be instantiated and called as such: RLEIterator obj = new
|
||||||
* RLEIterator obj = new RLEIterator(encoding);
|
* RLEIterator(encoding); int param_1 = obj.next(n);
|
||||||
* int param_1 = obj.next(n);
|
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue