Skip to content

Instantly share code, notes, and snippets.

View marklin-latte's full-sized avatar

MarkLin marklin-latte

View GitHub Profile
// Bug Version
function createArrayOfFunctions(y) {
var arr = [];
for(var i = 0; i<y; i++) {
arr[i] = function(x) { return x + i; } // <=== the i is bug ! the i will always be y+1;
}
return arr;
}
#include <iostream>
#include <string>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <vector>
#include <unordered_map>
using namespace std;
#include <iostream>
#include <string>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <vector>
using namespace std;
/**
function g(n){
let res = 0;
for (let i=1; i <= n; i++){
let temp = i;
while(temp != 0){
let digit = temp % 10;
if(digit == 7){
res++;
break;
}
@marklin-latte
marklin-latte / .cpp
Created April 21, 2019 08:44
148. Sort List
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
@marklin-latte
marklin-latte / .cpp
Created April 21, 2019 08:08
Leetcode 133 clone graph (c++)
/*
// Definition for a Node.
class Node {
public:
int val;
vector<Node*> neighbors;
Node() {}
Node(int _val, vector<Node*> _neighbors) {
public class Solution {
public int result;
/**
* @param amount: a total amount of money amount
* @param coins: the denomination of each coin
* @return: the number of combinations that make up the amount
*/
public int change(int amount, int[] coins) {
// write your code here
if(coins == null || coins.length == 0 ){
@marklin-latte
marklin-latte / coinchane.js
Created January 7, 2018 08:42
322. Coin Change
/**
* @param {number[]} coins
* @param {number} amount
* @return {number}
*/
var coinChange = function(coins, amount) {
// Using the greedy method. (Finding the maximum benefit.)
// 1. First, we should select the maximum denomination.
// 2. then, we should select the second largest coin.
@marklin-latte
marklin-latte / binaryTreePaths.js
Last active January 7, 2018 08:44
#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[]}
@marklin-latte
marklin-latte / gist:9998a13d19f70191a7f9754918e25d2b
Last active December 14, 2017 09:20
Second Minimum Node In a Binary Tree (未整理)
var findSecondMinimumValue = function(root) {
let stack = [];
let pre_val = 999999;
let temp_count = 1;
let result = 0;
stack.push(root);
let current;
while (stack.length > 0) {
current = stack.pop();