Skip to content

Instantly share code, notes, and snippets.

@wintercn
wintercn / reverseKGroupFromEnd.js
Created December 15, 2019 16:35
reverseKGroupFromEnd
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} head
* @param {number} k
<body style="margin:0;">
<div id="app" style="position:relative;width:100%;height:100%;">
</div>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>
Vue.component('local-storage', {
props: ['value', 'key'],
template: `<div></div>`,
mounted(){
if(!localStorage[this.$props.key])
Vue.component('local-storage', {
props: ['value', 'key'],
template: `<div></div>`,
mounted(){
if(!localStorage[this.$props.key])
return;
var str = JSON.stringify(this.$props.value);
if(str != localStorage[this.$props.key])
this.$emit('input', JSON.parse(localStorage[this.$props.key]))
},
<a href="javascript:void 0;">abc</a>
<div id="editor" contentEditable="true" style="white-space:pre;">
abc
</div>
<div id="editor2" contentEditable="true" style="white-space:pre;">
abc
@wintercn
wintercn / HTMLLexicalParser.js
Last active August 5, 2019 11:16
HTML语法分析器模型
function StartTagToken(){
}
function EndTagToken(){
}
function Attribute(){
}
@wintercn
wintercn / tang.html
Created April 21, 2019 13:46
tang.js
<meta charset="utf-8">
<body style="text-align:center">
<canvas width="1000" height="1000" style="background:black;margin:auto;">
</canvas>
<script src="tang.js">
</script>
</body>
@wintercn
wintercn / yc.js
Last active April 3, 2019 17:52
ycombinator in es2015
//yc here
var y = g =>
(f=>f(f))(
self =>
g( (...args)=>self(self)(...args) )
)
//use yc
var f = y(self =>
n => n < 0 ? 0 : n + self(n-1))
@wintercn
wintercn / sim.html
Last active March 31, 2019 03:57
贝塞尔曲线模拟二次曲线
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style>
.ball {
width:10px;
height:10px;
@wintercn
wintercn / coins.js
Last active March 23, 2019 13:33
现在有1分、2分、5分的硬币各无限枚,要凑成1元有多少种凑法?
function getResult(n,coins) {
var a = new Array(n+1);
for(var i = 0; i <= n;i++)
a[i] = 0;
a[0] = 1;
for(var j = 0; j<coins.length; j++)
var mSum = (m, n, a) =>
a.length ? m > 2 ? mSum(m, n, a.slice(0, a.length - 1)).concat(
mSum(m - 1 , n - a[a.length - 1], a.slice(0, a.length - 1)).map(e => e.concat([a[a.length - 1]]))) :
twoSum(n, a) :
[];
var twoSum = (n, a) => {
a.sort((x, y) => x - y);
var r = [];
if(a.length < 2) return r;