leetcode刷题笔记
Inuchiyo_chin
这个作者很懒,什么都没留下…
展开
-
[LeetCode]Spiral Matrix
class Solution { public: vector spiralOrder(vector>& matrix) { // Start typing your C/C++ solution below // DO NOT write int main() function if(matrix.size() == 0转载 2017-04-18 00:20:53 · 345 阅读 · 0 评论 -
Remove Duplicates from Sorted List2
递归分支的方法进行求解。 leetcode 82原创 2017-05-07 11:07:44 · 394 阅读 · 0 评论 -
leetcode[63] Minimum Path Sum 动态规划
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right whichminimizes the sum of all numbers along its path. Note: You can only move either down or right a转载 2017-04-24 09:59:27 · 381 阅读 · 0 评论 -
Rotate List
题目:输入k和链表的头结点,循环右移链表的后K个结点。 For example: Given1->2->3->4->5->NULLand k =2, return4->5->1->2->3->NULL. 思路: 1.首先要找链表的倒数第K个结点; 2.因循环右移的K个结点仍是按原来顺序排列,可考虑用一个先进先出的容器 即队列 将 后K个结点 存储,依原创 2017-04-20 21:02:54 · 293 阅读 · 0 评论 -
leetcode[60]Permutation Sequence 以及 全排列的编码与解码——康托展开 (附完整代码)
leetcode[60]Permutation Sequence 以及 全排列的编码与解码——康托展开 (附完整代码)原创 2017-04-20 10:45:06 · 763 阅读 · 0 评论 -
Leetcode 68. Text Justification
vector<string> fullJustify(vector<string>& words, int maxWidth) { vector<string> rs; int L = maxWidth; //得预先判断后一个单词的长度对,数组行长度的影响,j=i+1 for(int i=0 ; i<words.size(); ) //i固定在每行开头的单词,原创 2017-05-10 21:48:08 · 398 阅读 · 0 评论 -
leetcode[59]Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For example, Given n = 3, You should return the following matrix: [ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ] ] Subscribe to see which companies asked this que原创 2017-04-20 12:32:57 · 332 阅读 · 0 评论 -
LeetCode:N-Queens I (n皇后问题)
转载来自http://www.cnblogs.com/TenosDoIt/p/3801621.html博客园 LeetCode:N-Queens I II(n皇后问题)转载 2017-04-16 10:46:31 · 572 阅读 · 0 评论 -
LeetCode:Subsets
这道题可以使用两种方法求解,1使用位操作, 2深度优先的方法转载 2017-05-01 11:44:04 · 275 阅读 · 0 评论 -
leetcode 77. Combinations
这道题目可以用动态规划的思想解决:1~n中k个数的所有组合一定是由两部分组成:第一部分,求(1~n-1)中k-1个数的所有组合,然后每个组合中加入元素n; 第二部分,求(1~n-1)中k个数的所有组合; 上述两部分合并便可以得到1~n中k个数的所有组合。 还可以用DFS原创 2017-04-30 11:08:20 · 380 阅读 · 0 评论 -
leetcode 75. Sort Colors
首先是一个计数的思路:代码如下不难理解。 void sortColors(vector<int>& nums) { if (nums.empty()) return; //初始化一个count数组,count[0] , count[1] , count[2] 分别记录nums中0 , 1 , 2出现个数 vector<int> count(3, 0);原创 2017-04-30 10:39:41 · 275 阅读 · 0 评论 -
leetcode 73 Set Matrix Zeroes
leetcode 73原创 2017-04-29 10:32:03 · 306 阅读 · 0 评论 -
84. Largest Rectangle in Histogram
height的内容是 [5,6,7,8,3],特点是除了最后一个,前面全部保持递增,且最后一个立柱的高度小于前面所有立柱高度。 对于这种特点的柱状图,如果使用上面所说的“挨个使用每一个柱状图的高度作为矩形的高度,求面积”的方法,还需要用嵌套循环吗? 我们知道除了最后一个,从第一个到倒数第二个立柱的高度都在升高,那么如果挨个使用每一个柱的高度作为矩形的高度,那么依次能得到的矩形的宽度就可以直接算出原创 2017-05-18 09:20:31 · 405 阅读 · 0 评论