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
var charCodes= { | |
"a": ". _", | |
"b": "_ . . .", | |
"c": "_ . _ .", | |
"d": "_ . .", | |
"e": ".", | |
"f": ". . _ .", | |
"g": "_ _ .", | |
"h": ". . . .", | |
"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
// ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9 | |
// ["4", "13", "5", "/", "+"] -> (4 + (13 / 5)) -> 6 | |
var arr1 = ["2", "1", "+", "3", "*"]; // 9 | |
var arr2 = ["4", "13", "5", "/", "+"]; // 6 | |
// lifted from jQuery | |
var inArray = function (elem, arr, i) { | |
var len; | |
if (arr) { |
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
// naive approach | |
// Naively, we can simply examine every substring and check if it is palindromic. | |
// The time complexity is O(n^3).// Therefore, this approach is just a start, we need a better algorithm. | |
var longestPalindrome1 = function (string) { | |
var maxPalinLength = 0, | |
longestPalindrome = null, | |
length = string.length; | |
// check all possible sub strings | |
for (var i = 0; i < 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
/** | |
* Computes the longest palindromic substring in linear time | |
* using Manacher's algorithm. | |
* | |
* Credits: The code is lifted from the following excellent reference | |
* http://www.leetcode.com/2011/11/longest-palindromic-substring-part-ii.html | |
**/ | |
var Manacher = (function () { | |
var palindromic = [], // p[i] = length of longest palindromic substring of t, centered at 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
// Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. | |
// For example, given | |
var string = "leetcode", | |
dict = ["leet", "code"]; | |
// Return true because "leetcode" can be segmented as "leet code". | |
// 1. Naive Approach | |
// This problem can be solve by using a naive approach, which is trivial. A discussion can always start from that though. | |
// Time is O(n^2) and exceeds the time limit. | |
var wordBreak = function (string, dict) { |
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 dictionary of words dict, add spaces in s to construct a sentence where each | |
// word is a valid dictionary word. Return all such possible sentences. For example, given: | |
// s = "catsanddog", dict = ["cat", "cats", "and", "sand", "dog"], the solution is ["cats and dog", "cat sand dog"]. | |
// need to track the actual matched words | |
var wordBreak = function (string, dict) { | |
//create an array of ArrayList<String> | |
var dp = [string.length + 1]; | |
dp[0] = []; | |
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
// old school double loop | |
// quadratic O(n^2) inefficiency | |
var unique = function(array) { | |
var arr = [], | |
len = array.length; | |
for (var idx = 0; idx < len; i++) { | |
for(var jdx = i + 1; jdx < len; jdx++) { | |
if (array[idx] === array[jdx]) { | |
j = ++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
#!/bin/sh | |
# Alot of these configs have been taken from the various places | |
# on the web, most from here | |
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx | |
# Set the colours you can use | |
black='\033[0;30m' | |
white='\033[0;37m' | |
red='\033[0;31m' |
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
// variables for panel splitter; | |
var panelSplitterWidth = { | |
defaultW: null, | |
currentW: null | |
}; | |
// fires on mousedown on panel splitter draggable area | |
var panelSplitterClick = function(event) { | |
var $dragPanel = $(event.Event.target).closest("td:not('.af_panelSplitter_horizontal-icon-container')"); |
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
#!/bin/sh | |
# Install Homebrew | |
which -s brew | |
if [[ $? != 0 ]] ; then | |
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
else | |
brew update | |
fi |