This file contains hidden or 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
| 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) |
This file contains hidden or 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 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>(); |
This file contains hidden or 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 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; |