Skip to content

Instantly share code, notes, and snippets.

View seanzhu's full-sized avatar

Bin Zhu seanzhu

View GitHub Profile
@seanzhu
seanzhu / nestList.py
Created April 22, 2014 06:36
Flatten a nested list. Python version.
nestedList = [1, [2, [3, 4]], [5, 6, 7], 8, [[9, 10]]]
def flatten(nestedList):
return sum(([i]
if not isinstance(i, list)
else flatten(i)
for i in nestedList), [] )
print nestedList
print flatten(nestedList)
@seanzhu
seanzhu / NestList.java
Created April 22, 2014 06:35
Flatten a nested list. Java version.
package practice;
import java.util.LinkedList;
import java.util.List;
import static java.util.Arrays.asList;
public class NestList {
public static List<Integer> flatten(List<?> list) {
List<Integer> ret = new LinkedList<Integer>();
@seanzhu
seanzhu / gist:9753525
Created March 25, 2014 01:15
My solutions to leetcode problems in Java
package leetcode;
/**
* Created by sean on 3/24/14.
*/
public class ReverseWordsInString {
public static String reverseWords(String s) {
if (s.isEmpty() || s.length() == 0)
return s;