- 博客(15)
- 问答 (2)
- 收藏
- 关注
原创 leetcode No191. Number of 1 Bits
Question: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 32-bit integer ’11' has binary represen
2016-09-30 15:54:04 717
原创 leetcode No65. Valid Number
Question: Validate if a given string is numeric. Some examples: "0" => true " 0.1 " => true "abc" => false "1 a" => false "2e10" => true Note: It is intended for the problem statemen
2016-09-23 16:20:53 721
原创 leetcode No42. Trapping Rain Water
Question: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0
2016-09-21 21:17:15 1868
原创 leetcode No41. First Missing Positive
Question: Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2. Your algorithm should run in O(n) time and
2016-09-20 21:38:53 1410
原创 leetcode No4. Median of Two Sorted Arrays
Question: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example
2016-09-19 17:17:15 1007
原创 leetcode No322. Coin Change
Question: You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that a
2016-09-13 16:03:10 1268 2
原创 leetcode No131. Palindrome Partitioning
Question: Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s = "aab", Return [
2016-09-07 19:32:33 690
原创 Tree-Traversing Binary Tree
Traversing Binary Tree-二叉树的遍历 Definition: 二叉树的遍历是指从根结点出发,按照某种次序依次访问二叉树中所有结点,使得每个结点被访问一次且仅被访问一次。这里有两个关键词,访问和次序。 Traversal Method: 1、Preorder Traversal 规则是若二叉树为空,则空操作返回,否则先访问根结点,然后前序遍历左子树,再前序遍历右子树。
2016-09-05 16:43:14 513
原创 leetcode No129. Sum Root to Leaf Numbers
Question: Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123.
2016-09-04 22:54:47 854
原创 Sorting Algorithm-Summarize
从算法的简单性能来看,我们将这些排序算法分为两类: 简单排序:冒泡、简单选择、直接插入 改进算法:希尔、堆、归并、快速 从平均情况来看,显然最后3种改进算法要胜过希尔排序,并远远胜过前3种简单算法。 从最好情况看,反而冒泡和直接插入排序要更胜一筹,也就是说,如果你的待排序序列总是基本有序,反而不应该考虑4中复杂的还进算法。 从最坏情况来看,堆排序与归并排序又强过快速排序以及其他简单排序。
2016-09-04 17:47:03 578
原创 Sorting Algorithm-Quick Sort
Quick Sort-快速排序 快速排序(Quick Sort)的基本思想是:通过一趟排序将待排记录分割成独立的两部分,其中一部分记录的关键字均比另一部分记录的关键字小,则可分别对这两部分记录继续进行排序,以达到整个序列有序的目的。 Ex: 以第一个元素5为key,第一轮循环,要把小于5的元素放左边,大于等于5的放右边 接着递归,5左边的2,1,4,3重复,5右边的7,8,6,9重
2016-09-04 11:25:39 777
原创 Sorting Algorithm-Merging Sort
Merging Sort-归并排序 Algorithm: 归并排序就是利用归并的思想实现排序的方法。它的原理是假设初始序列含有n个记录,则可以看成是n个有序的子序列,每个子序列的长度为1,然后两两归并,得到[n/2]([x]表示不小于x的最小整数)个长度为2或1的有序子序列;再两两归并,...,如此重复,直至得到一个长度为n的有序序列为止,这种排序方法称为2路归并排序。 Ex:
2016-09-04 10:33:47 661
原创 Sorting Algorithm-Heap Sort
Heap Sort-堆排序 Algorithm: 堆排序就是利用堆(假设是大顶堆)进行排序的方法。它的基本思想是,将待排序的序列构造成一个大顶堆。此时,整个序列的最大值就是堆顶的根结点。将它移走(其实就是将其与堆数组的末尾元素交换,此时末尾元素就是最大值),然后将剩余的n-1个序列重新构造成一个堆,这样就会得到n个元素的次大值。如此反复执行,便能得到一个有序序列了。 Ex:大顶堆定义
2016-09-03 10:31:31 644
原创 leetcode No116. Populating Next Right Pointers in Each Node
Question: Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its next
2016-09-02 16:47:20 658
原创 leetcode No114. Flatten Binary Tree to Linked List
Question: 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 li
2016-09-02 11:58:42 710
空空如也
hexo 搭建博客-hexo new出错
2017-03-16
stable_partition怎么实现的
2016-10-08
TA创建的收藏夹 TA关注的收藏夹
TA关注的人