This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestClass { | |
public TestClass() { | |
print(); | |
public void print() { | |
System.out.println(this.getClass() + ": a:" + this.a + ", b:" + this.b); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestClass { | |
public TestClass() { | |
print(); | |
public void print() { | |
System.out.println(this.getClass() + ": a:" + this.a + ", b:" + this.b); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestClass { | |
public TestClass() { | |
print(); | |
public void print() { | |
System.out.println(this.getClass() + ": a:" + this.a + ", b:" + this.b); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestClass { | |
int a; | |
int b; | |
public TestClass() { | |
a = 5; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestClass { | |
int a; | |
int b; | |
public TestClass() { | |
a = 5; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestClass { | |
int a; | |
int b; | |
public TestClass() { | |
print(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String y = "Possible"; | |
private String n = "Impossible"; | |
public String ableToSolve(String s) { | |
if (s == null) return n; | |
if (s.isEmpty()) return y; | |
if (s.length() % 2 != 0) return n; | |
Stack<Character> stack = new Stack<Character>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DeepIterator implements Iterator<Integer> { | |
private Stack<Iterator> iteratorStack = new Stack<Iterator>(); | |
private Integer top = null; | |
public DeepIterator(Iterable iterable){ | |
this.iteratorStack.push(iterable.iterator()); | |
} | |
@Override | |
public boolean hasNext() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args){ | |
List list1 = new LinkedList(); | |
list1.add(0); | |
list1.add(new LinkedList<Integer>()); | |
list1.add(1); | |
list1.add(new LinkedList<Integer>()); | |
List list2 = new LinkedList(); | |
list2.add(list1); | |
list2.add(2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the naive idea to serialize the tree into an array, modify the values, but keep the left/right child | |
// intact, but this uses extra O(N) space and O(N) time | |
public void serializeTreeSum(TreeNode node) { | |
List<TreeNode> nodes = new ArrayList<>(); | |
this.inorderTraversal(node, nodes); | |
// nodes is sorted ascendingly after inorder traversal, keep a rolling sum | |
int rollingSum = 0; | |
for (int i = nodes.size() - 1; i >= 0; i--) { | |
nodes.get(i).val = nodes.get(i).val + rollingSum; |
OlderNewer