This file contains hidden or 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
// 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; | |
} |
This file contains hidden or 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
#include <iostream> | |
#include <string> | |
#include <iostream> | |
#include <algorithm> | |
#include <math.h> | |
#include <limits.h> | |
#include <vector> | |
#include <unordered_map> | |
using namespace std; |
This file contains hidden or 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
#include <iostream> | |
#include <string> | |
#include <iostream> | |
#include <algorithm> | |
#include <math.h> | |
#include <limits.h> | |
#include <vector> | |
using namespace std; | |
/** |
This file contains hidden or 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
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; | |
} |
This file contains hidden or 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
/** | |
* Definition for singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode(int x) : val(x), next(NULL) {} | |
* }; | |
*/ | |
class Solution { | |
public: |
This file contains hidden or 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
/* | |
// Definition for a Node. | |
class Node { | |
public: | |
int val; | |
vector<Node*> neighbors; | |
Node() {} | |
Node(int _val, vector<Node*> _neighbors) { |
This file contains hidden or 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
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 ){ |
This file contains hidden or 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
/** | |
* @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. |
This file contains hidden or 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
/** | |
* Definition for a binary tree node. | |
* function TreeNode(val) { | |
* this.val = val; | |
* this.left = this.right = null; | |
* } | |
*/ | |
/** | |
* @param {TreeNode} root | |
* @return {string[]} |
This file contains hidden or 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 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(); | |
NewerOlder