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
/** | |
* Definition for singly-linked list. | |
* function ListNode(val) { | |
* this.val = val; | |
* this.next = null; | |
* } | |
*/ | |
/** | |
* @param {ListNode} l1 | |
* @param {ListNode} l2 |
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
/** | |
* @param {string} s | |
* @return {string} | |
*/ | |
var longestPalindrome = function(s) { | |
if (!s) return ''; | |
var longest = s[0]; | |
var expandAroundCenter = function (left, right) { | |
while (left >= 0 && right < s.length && s[left] === s[right]) { | |
left--; |
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
function curry(fn) { | |
var args = [] | |
var len = fn.length | |
var result = function(n) { | |
args.push(n) | |
len-- | |
if (len > 0) { | |
return result | |
} else { |
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
function fn(n) { | |
if (n < 1) { | |
return 0 | |
} | |
if (n === 1) { | |
return 1 | |
} | |
if (n === 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
/** | |
* @param {string} s | |
* @return {string} | |
*/ | |
var longestPalindrome = function(s) { | |
var len = s.length | |
var maxLen = 0 | |
var res = '' | |
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
function quickSort(arr) { | |
// 交换元素 | |
function swap(arr, a, b) { | |
var temp = arr[a]; | |
arr[a] = arr[b]; | |
arr[b] = temp; | |
} | |
function partition(arr, left, right) { | |
var pivot = arr[left]; |
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
// ES5版本 | |
function shuffle(a) { | |
var i,j,t | |
for(i = a.length; i; i--) { | |
j = Math.floor(Math.random() * i) | |
t = a[i-1] | |
a[i-1] = a[j] | |
a[j] = t | |
} | |
return a |
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
function add() { | |
var sum = 0; | |
function add() { | |
for (var i=0; i<arguments.length; i++) { | |
sum += Number(arguments[i]); | |
} | |
return add; | |
} | |
add.valueOf = function valueOf(){ |
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
function throttle(func, wait, options) { | |
var timeout, context, args | |
var previous = 0 | |
if (!options) options = {} | |
var later = function() { | |
previous = options.leading === false ? 0 : Date.now() | |
timeout = null | |
func.apply(context, args) |
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
function debounce(func, wait, immediate) { | |
var timeout | |
return function() { | |
var context = this | |
var args = arguments | |
if(timeout) clearTimeout(timeout) | |
if (immediate) { |
NewerOlder