Skip to content

Instantly share code, notes, and snippets.

@chuchao333
chuchao333 / about.md
Created September 14, 2011 16:36 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
@chuchao333
chuchao333 / good_insights_about_interview.rst
Created February 15, 2012 08:06
Tips of the Day 20120215

Giesen, Stefan

To be honest, I am doing extensive UNIX shell programming for over 20 years now and as (far as I can remember) I never had to use “$?”even once (and “$!” maybe 5 or 6 times in all those years – I actually had to look both of them up right now to see what they are standing for…). Which of course means that – according to your test – I am not very experienced regarding shell programming, am I?

Asking for something which can be found out with a simple ‘man bash’ when I need it is IMHO not a good way to check how experienced people are, but how good their memorizing skills are. Most people mix those two things up all the times. In my personal experience most of the people who can memorize everything aren’t always the best programmers (I often found that quite the opposite is actually true, besides some remarkable exceptions), but of course YMMV…

The same is true when asking for some exotic options to well known commands (e.g. asking what the option “-h” of tar does – do you know

@chuchao333
chuchao333 / ubt.py
Last active August 29, 2015 14:09
Unique Binary Trees @ LeetCode
"""
class Solution {
public:
int numTrees(int n) {
if (n == 1)
return 1;
int res = 0;
// for each of the middle nodes, the number is the product of its left and right children
for (int i = 2; i <= n - 1; ++i)
@chuchao333
chuchao333 / llc.cpp
Created November 18, 2014 07:23
Linked List Cycle
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
@chuchao333
chuchao333 / solution.cpp
Created November 22, 2014 08:58
Populating Next Right Pointers in Each Node
/**
* Definition for binary tree with next pointer.
* struct TreeLinkNode {
* int val;
* TreeLinkNode *left, *right, *next;
* TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL) {}
* };
*/
class Solution {
public:
@chuchao333
chuchao333 / searchInsert.cpp
Created November 23, 2014 15:35
Search Insert Position
class Solution {
public:
int searchInsert(int A[], int n, int target) {
int low = 0, high = n;
// search in the interval A[low, high)
while (low < high) {
// loop invariant
// 1) 0 <= low < high <= n
// 2) (low == 0 || A[low - 1] < target)
// 3) (high == n || A[high] > target)
@chuchao333
chuchao333 / divide_and_conquer.cpp
Created December 1, 2014 19:10
Maximum Subarray
#include <limits>
class Solution {
public:
int maxSubArray(int A[], int n) {
if (n == 1)
return A[0];
auto mid = n / 2;
@chuchao333
chuchao333 / solution.cpp
Created December 4, 2014 07:02
Remove Duplicates from Sorted List
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public: