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
//use space | |
var sortColors1 = function(nums) { | |
const pivot = nums[0]; | |
let left = []; | |
let right = []; | |
let i = 0; | |
while(i < nums.length -1) { | |
nums[i] < pivot ? left.push(nums[i]) : right.push(nums[i]) | |
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 topKFrequent = function(nums, k) { | |
let hash = {} | |
nums.forEach(row => { | |
if(hash[row] === undefined) { | |
hash[row] = 1; | |
}else { | |
hash[row] += 1; | |
} | |
}) | |
let res = [...hash].sort((a,b) => a[1]-b[1]) |
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
//Topic: find Kth elements | |
//quick sort use space | |
var qsort = function(nums,k) { | |
if(nums.length <= 1) { | |
return nums | |
} | |
let leftAry = []; | |
let rightAry = []; |
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 toLowerCase = function(str) { | |
return str.toLowerCase(); | |
}; |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
li.active { | |
text-decoration: line-through; | |
} |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
li.active { | |
text-decoration: line-through; | |
} |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div id="app"> | |
<div v-if="loading">loading中</div> |