This file contains 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
/* | |
http://oj.leetcode.com/problems/trapping-rain-water/ | |
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. | |
For example, | |
Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6. | |
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for contributing this image! | |
*/ |
This file contains 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
/* | |
http://oj.leetcode.com/problems/binary-tree-level-order-traversal-ii/ | |
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). | |
For example: | |
Given binary tree {3,9,20,#,#,15,7}, | |
return its bottom-up level order traversal as: |
This file contains 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
/* | |
http://oj.leetcode.com/problems/interleaving-string/ | |
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. | |
For example, | |
Given: | |
s1 = "aabcc", | |
s2 = "dbbca", |
This file contains 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
/* | |
Find the kth smallest number in the binary search tree. | |
*/ | |
#include <cstdio> | |
#include <stack> | |
#include <queue> | |
struct TreeNode { | |
int val; |
This file contains 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
/* | |
Given a binary tree, return the inorder traversal of its nodes' values. | |
For example: | |
Given binary tree {1,#,2,3}, | |
1 | |
\ | |
2 | |
/ | |
3 |
This file contains 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
#include <cstdio> | |
#include <vector> | |
#include <algorithm> | |
class Solution { | |
public: | |
int threeSumClosest(std::vector<int> &num, int target) { | |
int closest = num[0] + num[1] + num[2]; | |
std::sort(num.begin(), num.end()); |
This file contains 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
# Bash command aliases and utils | |
# code format | |
function astyle-java { | |
astyle --mode=java --style=linux -s4 $@ | |
} | |
function astyle-c { | |
astyle --mode=c --style=linux -s4 $@ | |
} |
This file contains 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
abstract class Boolean { | |
def == (other: Boolean): Boolean; | |
def != (other: Boolean): Boolean; | |
def && (other: Boolean): Boolean; | |
def || (other: Boolean): Boolean; | |
def unary_! (): Boolean; | |
} | |
object True extends Boolean { | |
def == (other: Boolean) = other; |
This file contains 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
#!/usr/bin/env perl | |
use File::Basename | |
$nargs = @ARGV; | |
sub usage() { | |
my $prog = basename($0); | |
print "Usage: $prog <start-text> <end-text>\n"; | |
} |
This file contains 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
package list.length | |
object Main { | |
def f(arr: List[Int]): Int = arr match { | |
case x :: xs => 1 + f(xs) | |
case _ => 0 | |
} | |
def main(args: Array[String]) { | |
val len = f(List(1, 2, 3)); |
OlderNewer