Skip to content

Instantly share code, notes, and snippets.

View tin80122's full-sized avatar

Sasa tin80122

View GitHub Profile
@tin80122
tin80122 / leetCode75.js
Created March 13, 2021 01:51
LeetCode 75 Quick Sort in place
//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++;
}
@tin80122
tin80122 / leetCode347.js
Created March 13, 2021 01:49
CodePen Home LeetCode 347 bucket sort
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])
@tin80122
tin80122 / leetCode215.js
Last active March 16, 2021 08:35
LeetCode 215 Quick Sort space, Insert Sort
//Topic: find Kth elements
//quick sort use space
var qsort = function(nums,k) {
if(nums.length <= 1) {
return nums
}
let leftAry = [];
let rightAry = [];
var toLowerCase = function(str) {
return str.toLowerCase();
};
<!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;
}
<!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;
}
<!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>