`
dugu108
  • 浏览: 23195 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论
文章列表

js闭包是什么?

尽管本身不太会js,不过通过这个文章理解了闭包   js闭包是什么? js闭包是什么?我初次接触“闭包”时,看了很多资料,总是无法理解,因为一些文章写得太“学术化”,虽然措辞非常严谨,但是对初学这来说,太难理解了。   自从看到这篇文章,我的眼前“豁然开朗”     一、什么是闭包?     “官方”的解释是:所谓“闭包”,指的是一个拥有许多变量和绑定了这些变量的环境的表达式(通常是一个函数),因而这些变量也是该表达式的一部分。     相信很少有人能直接看懂这句话,因为他描述的太学术。我想用如何在Javascript中创建一个闭包来 ...

堆Heap

public class Heap { public static void siftUp(int[] array, int i) { if (array == null || array.length <= 1 || i < 0 || i > array.length) { return; } while (true) { if (array[(i - 1) / 2] < array[i]) { swap(array, i, (i - 1) / 2); } else { break; } ...
分别是利用一个辅助栈和两个辅助栈 public class StackSort { public static void sortWithOneCache(Stack<Integer> stack) { if (stack == null || stack.isEmpty()) { return; } Stack<Integer> cache = new Stack<Integer>(); while (!stack.isEmpty()) { int tmp = stack.pop(); while ...
找出二叉查找树Binary search tree上任意两个节点的最近共同父节点    public class Solution { public static int findFather(BinarySearchTreeNode root, BinarySearchTreeNode n1, BinarySearchTreeNode n2) { if (n1.value < root.value && n2.value > root.value) { return root.value; ...
Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6   The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ ...
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, " ...
  Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binary tree? Would your previous solution still work? Note: You may only use constant extra space.   For example,Given the following binary tree, 1 / \ ...
  Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }   Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set toNULL. Initially, all next poi ...

Pascal's Triangle II

Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3,3,1]. Note:Could you optimize your algorithm to use only O(k) extra space? import java.util.ArrayList;

Pascal's Triangle

  Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] public class Solution { public ArrayList<ArrayList<Integer>> generate(int numRows) { ArrayList&l ...
给定一无序整型数组a,在不排序的情况下,查找第k小的元素 类似快排。 如果k非常小比如小于3,觉得应该用几个临时变量然后遍历一遍解决。   public class MinKth { public static int calculate(int[] array, int k) { return calculate(array, k, 0, array.length - 1); } public static int calculate(int[] array, int k, int low, int high) { ...

Triangle

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle [ [2], [3,4], [6,5,7], [4,1,8,3] ]   The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11 ...
Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactio ...
Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.   public class Solution { public int maxProfit(in ...
  Given a binary tree, find the maximum path sum. The path may start and end at any node in the tree. For example:Given the below binary tree, 1 / \ 2 3   Return 6.   /** * Definition for binary tree public class TreeNode { int val; TreeNode left; * TreeNode righ ...
Global site tag (gtag.js) - Google Analytics