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
| #!/usr/bin/env node | |
| function make_stack() { | |
| return null | |
| } | |
| function push(stack, x) { | |
| return { | |
| top : function() { return x }, | |
| pop : function() { return stack } |
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
| /* | |
| Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n). | |
| For example, | |
| S = "ADOBECODEBANC" | |
| T = "ABC" | |
| Minimum window is "BANC". | |
| Note: | |
| If there is no such window in S that covers all characters in T, return the emtpy string "". |
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
| /* | |
| Given an array of integers, find two numbers such that they add up to a specific target number. | |
| The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based. | |
| You may assume that each input would have exactly one solution. | |
| Input: numbers={2, 7, 11, 15}, target=9 | |
| Output: index1=1, index2=2 | |
| */ |
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
| push = (element) -> (stack) -> | |
| newStack = [element].concat stack | |
| {value: element, stack: newStack} | |
| pop = (stack) -> | |
| element = stack[0] | |
| newStack = stack.slice 1 | |
| {value: element, stack: newStack} | |
| bind = (stackOperation, continuation) -> (stack) -> |
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
| public class LCS { | |
| public static void main(String... args) throws Exception { | |
| System.out.println(lcs("Milexxs", "xxxxxxxM")); | |
| } | |
| public static String lcs(String a, String b) { | |
| if (null == a || null == b) return ""; | |
| String longest = ""; | |
| for (int i = 0; i < a.length(); ++i) { |
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
| /* | |
| 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 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
| /* | |
| 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 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
| /* | |
| 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 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
| /* | |
| Find the kth smallest number in the binary search tree. | |
| */ | |
| #include <cstdio> | |
| #include <stack> | |
| #include <queue> | |
| struct TreeNode { | |
| int val; |
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
| /* | |
| Given a binary tree, return the inorder traversal of its nodes' values. | |
| For example: | |
| Given binary tree {1,#,2,3}, | |
| 1 | |
| \ | |
| 2 | |
| / | |
| 3 |