自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

Stephen Wong的专栏

让明天把今天记住 不是因为孤独 因为我们追求的专注 不管它起起伏伏

  • 博客(49)
  • 收藏
  • 关注

原创 LeetCode 95. Unique Binary Search Trees

给定n, 求不同的BST的数目。

2014-07-27 07:16:59 740

原创 LeetCode 94. Binary Tree Inorder Traversal

树的中序遍历,递归。代码:class Solution {public: vector inorderTraversal(TreeNode *root) { vector ret; gao(root, ret); return ret; }private: void gao(TreeNode* node, vector

2014-07-27 07:16:39 738

原创 LeetCode 93. Restore IP Addresses

递归+剪枝。代码:class Solution {public: vector restoreIpAddresses(string s) { vector now; gao(now, 0, s, 0); return ret; }private: void gao(vector& now, int depth,

2014-07-27 07:06:32 914

原创 LeetCode 92. Reverse Linked List II

代码:class Solution {public: ListNode *reverseBetween(ListNode *head, int m, int n) { if (head==NULL || m==n) { return head; } ListNode *cut=head, *cur=head;

2014-07-27 06:55:49 683

原创 LeetCode 91. Subsets

排序S, 用vector num记录不同的数字,用vector cnt为这些数字计数。(怎么gan代码:

2014-07-26 05:14:16 752

原创 LeetCode 90. Decode Ways

0只能在10,20中出现,亦即字符串包含0时,前面的数字只能为1或2.

2014-07-26 05:09:39 818

原创 LeetCode 89. Gray Code

百度百科:格雷码第i个格雷码的数学解是

2014-07-26 05:01:31 717

原创 LeetCode 88. Merge Sorted Array

O(n+m)空间 O(n+m)时间实现代码:class Solution {public: void merge(int A[], int m, int B[], int n) { int i=0, j=0, index=m; vector vt(m+n, 0); while ( i<m && j<n ) {

2014-07-26 04:59:40 696

原创 LeetCode 87. Scramble String

递归+剪枝

2014-07-26 04:58:17 831

原创 LeetCode 86. Partition List

用两条链表维护两个partion, 最后把它们hebing

2014-07-23 04:54:26 721

原创 LeetCode 85. Maximal Rectangle

遍历matrix,用cnt[i][j]记录位置(i, j)起

2014-07-23 04:25:02 762

原创 LeetCode 84. Maximal Rectanglea (O(n)实现)

参考hackersun007的修行之路的题解。用一个站

2014-07-22 08:36:14 852

原创 LeetCode 83. Remove Duplicates from Sorted List II

代码:class Solution {public: ListNode *deleteDuplicates(ListNode *head) { auto cur = head; ListNode* pre_node = NULL; while (cur != NULL) { bool need = true;

2014-07-22 06:49:44 727

原创 LeetCode 81. Search in Rotated Sorted Array II

和LeetCode 32. Search in Rotated Sorted Array类似,二分递归求解。数组任意的一次向右滚动(一个单位),考虑最后两个元素A[n-1], A[n-2]. 若A[n-1]事实上为最初的A[0], 那么这次滚动后,数组将回到最初的状态,A[0'] , 成为升序数组,二分搜索即可;若A[n-1]并非最初的A[0], 那么必有A[n-2] A[0'] >=

2014-07-22 05:50:03 747

原创 LeetCode 82. Remove Duplicates from Sorted List

代码:class Solution {public: ListNode *deleteDuplicates(ListNode *head) { auto cur = head; while (cur != NULL) { auto next = cur->next; while (next!=NULL &&

2014-07-22 05:49:36 730

原创 LeetCode 80. Remove Duplicates from Sorted Array II

在升序数组中,每个数字最多只能出现2次。代码:class Solution {public: int removeDuplicates(int A[], int n) { int length = 0; for (int i=0; i < n; ) { A[length ++] = A[i ++]; if (i<n &&

2014-07-22 05:03:37 787

原创 LeetCode 79. Word Search

递归搜索即可,注意标记已访问过的点。代码:class Solution {public: bool exist(vector > &board, string word) { if (board.empty()==true || word.empty()==true) { return false; } size_t n=board.size(),

2014-07-17 09:53:54 830

原创 LeetCode 78. Subsets

和LeetCode 77. Combinations相似。求的是集合S的miji

2014-07-17 09:52:21 891

原创 LeetCode 77. Combinations

求C(n, k)的所有组合,递归求解即可。代码:

2014-07-17 09:50:03 887

原创 LeetCode 76. Minimum Window Substring

用头尾指针记录S的子串,当子串包含T中的所有字符时,尝试收缩头指针begin,

2014-07-17 01:15:00 703

原创 JavaScript学习笔记

JavaScript 101

2014-07-16 07:55:02 562

原创 LeetCode 75. Sort Colors (O(n) one pass实现)

用两个变量red, white记录当前最后一个红色、最后一个白色的坐标

2014-07-15 05:11:24 750

原创 LeetCode 74. Search a 2D Matrix

两次二分查找即可:先考察第0列的所有元素

2014-07-15 03:33:32 648

原创 LeetCode 73. Set Matrix Zeroes (O(nm)时间 O(1)空间实现)

要求用O(1)空间实现,O(nm)时间则是遍历矩阵每个元素必要的。

2014-07-15 03:11:43 902

原创 LeetCode 72. Edit Distance

自然语言处理(NPL)里的一个问题,用动态规划解。dp[i][j]表示word1前i个字符和word2前j个z

2014-07-14 10:34:35 872

原创 LeetCode 71. Simplify Path

以'/'切分路径。当前文件名为"."时忽略,

2014-07-13 09:21:33 635

原创 LeetCode 70. Climbing Stairs (O(n)时间, O(1)空间实现)

爬楼梯,一次爬1步或2步,求欲到达第n步,有几种爬法。

2014-07-12 07:23:50 890

原创 LeetCode 69. Sqrt(x)

解法一:二分代码:

2014-07-12 07:17:12 688

原创 LeetCode 68. Text Justification

写的不好看,下次改进了。

2014-07-12 05:53:27 723

原创 LeetCode 67. Plus One

代码:class Solution {public: vector plusOne(vector &digits) { int carry = 1; vector ret; for (int i = digits.size()-1; i >= 0; -- i) { ret.insert(ret.begin(), (di

2014-07-11 11:24:24 649

原创 LeetCode 66. Valid Number

1. 前导后导空格去掉2.

2014-07-11 11:23:01 834

原创 摘记

人与人之间最小的差别是智商,最大的差别是坚持。

2014-07-10 07:29:50 580

原创 LeetCode 65. Add Binary

字符串模拟二进制加法。代码:

2014-07-07 05:08:20 697

原创 STL: string

http://www.cplusplus.com/reference/string/string/strin

2014-07-07 05:06:07 625

原创 LeetCode 64. Merge Two Sorted List

和merge sort的写法类似,只是处理

2014-07-06 12:31:49 777

原创 LeetCode 63. Minimum Path Sum

一开始写了个用最小堆维护的dijkstra, xiang

2014-07-06 12:08:40 843

原创 LeetCode 62. Unique Path II

思路同 LeetCode 61. Unique Path

2014-07-04 13:27:22 769

原创 LeetCode 61. Unique Path

从原点出发,只能向右或向左移动。对于点阵中的任一点(i, j),

2014-07-04 13:20:55 635

原创 LeetCode 60. Rotate List

代码:class Solution {public: ListNode *rotateRight(ListNode *head, int k) { if (head == NULL) { return NULL; } int size = 0; auto fast = head, slow = head;

2014-07-04 06:09:18 522

原创 LeetCode 59. Permutation Sequence

代码:class Solution {public: string getPermutation(int n, int k) { int num[] = {0, 1, 2, 6, 24, 120, 720, 5040, 40320}; bool vi[10] = {false, false}; string ret = string(n, 0

2014-07-04 05:52:41 618

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除