Skip to content

Instantly share code, notes, and snippets.

View jack5241027's full-sized avatar

JackChan jack5241027

View GitHub Profile
@jack5241027
jack5241027 / Perfect Squares.js (BFS)
Last active April 21, 2019 10:26
279. Perfect Squares.js
/**
* @param {number} n
* @return {number}
*/
var numSquares = function(n) {
const squares = [];
for (let i = 1; i * i <= n; i++) {
squares.push(i*i);
}
@jack5241027
jack5241027 / .js
Created April 21, 2019 09:20
92. Reverse Linked List II (js)
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} head
* @param {number} m
@jack5241027
jack5241027 / 322. Coin Change - BFS
Created January 9, 2018 02:28
322. Coin Change - BFS
var coinChange = function (coins, amount) {
if (!amount) return amount;
let smallest = Infinity;
const helper = (val, path) => {
for (let i = 0; i < coins.length; i++) {
const nextVal = val + coins[i];
if (nextVal < amount) {
helper(nextVal, path.concat(coins[i]));
@jack5241027
jack5241027 / 322. Coin Change - Greedy
Created January 9, 2018 02:27
322. Coin Change - Greedy
const helper = (ary, amount) => {
const res = 0;
let current = ary.pop();
let left = amount;
let done = false;
let count = 0;
while (current && !done) {
const nextLeft = left - current;
if (nextLeft < 0) {
@jack5241027
jack5241027 / 257. Binary Tree Paths
Created January 6, 2018 14:22
257. Binary Tree Paths
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @return {string[]}
@jack5241027
jack5241027 / gh-pages-deploy.md
Created July 6, 2017 08:10 — forked from cobyism/gh-pages-deploy.md
Deploy to `gh-pages` from a `dist` folder on the master branch. Useful for use with [yeoman](http://yeoman.io).

Deploying a subfolder to GitHub Pages

Sometimes you want to have a subdirectory on the master branch be the root directory of a repository’s gh-pages branch. This is useful for things like sites developed with Yeoman, or if you have a Jekyll site contained in the master branch alongside the rest of your code.

For the sake of this example, let’s pretend the subfolder containing your site is named dist.

Step 1

Remove the dist directory from the project’s .gitignore file (it’s ignored by default by Yeoman).

@jack5241027
jack5241027 / webpack.js
Created December 20, 2016 20:37 — forked from couto/webpack.js
Fetch polyfill with webpack
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
var folders = {
APP: path.resolve(__dirname, '../app'),
BUILD: path.resolve(__dirname, '../build'),
BOWER: path.resolve(__dirname, '../bower_components'),
NPM: path.resolve(__dirname, '../node_modules')
};
@jack5241027
jack5241027 / myToReadBookLists.md
Created July 10, 2016 07:33 — forked from chusiang/myToReadBookLists.md
凍仁的讀書清單
@jack5241027
jack5241027 / README.md
Created June 28, 2016 00:16 — forked from jonathantneal/README.md
createElement.js // a 300 byte DOM Element creator

createElement.js

createElement.js lets document.createElement use CSS selectors.

This is a pretty useful library for building out DOM elements. The whole thing runs on one regex and a for loop, so it’s plenty fast. The script is 300 bytes when compressed and gzipped. For 524 bytes (advanced), it includes nesting support and can generate entire DOM hierarchies, including text nodes.

Usage

document.createElement(); // generates <div />
@jack5241027
jack5241027 / introrx.md
Created February 1, 2016 01:42 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing