Skip to content

Instantly share code, notes, and snippets.

View shixiaoyu's full-sized avatar
💭
Hello World :)

Xiaoyu shixiaoyu

💭
Hello World :)
View GitHub Profile
public class TestClass {
public TestClass() {
print();
public void print() {
System.out.println(this.getClass() + ": a:" + this.a + ", b:" + this.b);
public class TestClass {
public TestClass() {
print();
public void print() {
System.out.println(this.getClass() + ": a:" + this.a + ", b:" + this.b);
public class TestClass {
public TestClass() {
print();
public void print() {
System.out.println(this.getClass() + ": a:" + this.a + ", b:" + this.b);
public class TestClass {
int a;
int b;
public TestClass() {
a = 5;
public class TestClass {
int a;
int b;
public TestClass() {
a = 5;
public class TestClass {
int a;
int b;
public TestClass() {
print();
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>();
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() {
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 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;