Skip to content

Instantly share code, notes, and snippets.

// node.left -> node.right -> node
public void postorder(TreeNode root) {
Stack<Integer> stack1 = new Stack<>();
Stack<Integer> stack2 = new Stack<>();
stack1.push(root);
TreeNode current;
// node.left -> node -> node.right
public void inorder(TreeNode root) {
Stack<Integer> stack = new Stack<>();
TreeNode current = root;
while (!stack.empty() || current != null) {
if (current != null) {
stack.push(current);
# Preorder traversal: node -> node.left -> node.right
public void preorder(TreeNode root) {
Stack<TreeNode> stack = new Stack<>();
TreeNode current = root;
while (stack.size > 0 || current != null) {
if (current != null) {
visit(current);

Notes


.       - Any Character Except New Line
\d      - Digit (0-9)
\D      - Not a Digit (0-9)
\w      - Word Character (a-z, A-Z, 0-9, _)
\W      - Not a Word Character
\s - Whitespace (space, tab, newline)
@aqd14
aqd14 / functional-python
Created March 19, 2019 16:07
Examples on **lambda**, **map**, and **filter**
### Lambda
Syntax: ```lambda arguments: expression```
__Example__
```
# Regular way of creating a function
def add(x, y):
return x+y

Notes

Option 1: Using GitHub merge pull request button

Option 2: Execute followings steps

  1. Add requester's fork as a remote
  2. git fetch <remote>
  3. git merge <remote>/master
  4. git push
@aqd14
aqd14 / git-remote.md
Last active March 19, 2019 04:23
Connect with a remote repo to share the commits

Connect the local repo to the remote one

git remote add <name> <url>

git push -u origin master

# display all remote repos that currently connected with
git remote -v
```
git commit -m "title" -m "longer descriptions"
# or
git commit # an editor will be opened and you will be able to type your commit title and descriptions there
```
```
git config --global core.editor vim|emacs|nano
# Add flag --wait for your favorite editor in order to tell git
# to wait until I quit atom for the action to be completed
```
@aqd14
aqd14 / git-amend
Last active March 17, 2019 22:02
Just commited all the changes but forgot to add one or more files. Using `git commit --amend`
```
# Add the missing files from the previous commit
git add missing-file.txt
# Modify the last commit with new file added and/or new commit message
git commit --amend
```
`git commit --amend` can only be used when you forgot files from the last commit.