This file contains 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
bundle exec jekyll serve --drafts --config _config.yml,_config_dev.yml --watch |
This file contains 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
title: Baker's GitHub Repo DEVELOPMENT | |
url: http://localhost:4000 | |
baseurl: "" |
This file contains 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
// Problem: Rotate an array of n elements to the right by k steps. | |
// For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. | |
// How many different ways do you know to solve this problem? | |
var array = [1,2,3,4,5,6,7]; | |
var result = [5,6,7,1,2,3,4]; | |
// Solution 1 - Intermediate Array | |
function rotate(nums, k) { | |
var result = [], |
This file contains 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 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 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 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 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 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 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; |
OlderNewer