- 博客(10)
- 收藏
- 关注
转载 青蛙跳台阶问题
(1)一只青蛙一次可以跳上 1 级台阶,也可以跳上2 级。求该青蛙跳上一个n 级的台阶总共有多少种跳法。 (2)一只青蛙一次可以跳上1级台阶,也可以跳上2 级……它也可以跳上n 级,此时该青蛙跳上一个n级的台阶总共有多少种跳法? 分析:1)当n = 1, 只有1中跳法;当n = 2时,有两种跳法;当n = 3 时,有3种跳法;当n = 4时,有5种跳法;当n = 5时,
2016-02-29 11:47:26 238
原创 106. Construct Binary Tree from Inorder and Postorder Traversal
题目: Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 解题思路: 递归 /** * Definition for a binary tree
2016-02-29 09:57:45 209
原创 105. Construct Binary Tree from Preorder and Inorder Traversal
题目: Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 解题思路: /** * Definition for a binary tree node.
2016-02-26 20:13:22 267
原创 240. Search a 2D Matrix II
题目: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted in ascending from left to right.Int
2016-02-26 16:25:51 226
原创 74. Search a 2D Matrix
题目: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right.The first intege
2016-02-26 16:21:16 230
原创 46. Permutations
题目: Given a collection of distinct numbers, return all possible permutations. For example, [1,2,3] have the following permutations: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]
2016-02-26 14:37:33 244
原创 147. Insertion Sort List
题目: Sort a linked list using insertion sort. 解题思路: 插入排序在链表中运用。可运用递归,比较巧妙。 递归版本: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * List
2016-02-26 11:12:58 319
原创 148. Sort List
题目: Sort a linked list in O(n log n) time using constant space complexity. 解题思路: 使用对链表的归并排序。 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *nex
2016-02-26 09:50:12 203
原创 89. Gray Code
题目: The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the seq
2016-02-24 16:56:54 217
原创 328. Odd Even Linked List
题目: Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes. You should try to
2016-02-20 16:42:59 215
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人