Leetcode
文章平均质量分 67
Yanxi1122
这个作者很懒,什么都没留下…
展开
-
leetcode-59 Spiral Matrix
这是一道旋转矩阵的题,题目如下:Given an integer n, generate a square matrix filled with elements from 1 ton2 in spiral order.For example,Given n = 3, You should return the following matrix:[ [ 1, 2, 3原创 2017-04-07 15:22:25 · 170 阅读 · 0 评论 -
leetcode-73 set matrix zeros
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 题意是将矩阵中,有0的行列值均置为0.这道题想要原址,首先需要记录下首行、首列,是否有0。其次从2行2列开始统计,如果有0,则将此位置的首行、首列位置记为0,实现原址。在改的时候应当注意,首行首列的值原创 2017-04-25 11:49:03 · 300 阅读 · 0 评论 -
leetcode-71 simplify path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"路径打印问题,将自己碰到的特殊情况记录如下1.两个"//"打印为一个"/"2.出现两个点"/../"原创 2017-04-17 11:48:17 · 189 阅读 · 0 评论 -
leetcode-68 Text Justification
题目如下:Given an array of words and a length L, format the text such that each line has exactlyL characters and is fully (left and right) justified. You should pack your words in a greedy approach;原创 2017-04-14 11:40:50 · 214 阅读 · 0 评论 -
leetcode-67 add binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".题意是将两个二进制串相加本题与上题类似,都是从后向前相加,维护一个进位。写的比较繁琐class Solution {public: stri原创 2017-04-12 11:11:44 · 257 阅读 · 0 评论 -
leetcode-66 plus one
这道题,从后向前依次加和,需要记录下进位,和处理最后的进位class Solution {public: vector plusOne(vector& digits) { vector res; vector tempres; int jinwei=0; int n = digits.size(); int num = digits[n-1] + 1; i原创 2017-04-12 10:39:18 · 183 阅读 · 0 评论 -
leetcode-65 valid number
Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to be amb原创 2017-04-11 11:43:22 · 235 阅读 · 0 评论 -
leetcode-57 insert interval
有了上道题的基础,这道题将新来的interval插入到原来的intervals当中,然后进行融合即可Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were i原创 2017-03-31 10:07:02 · 179 阅读 · 0 评论 -
leetcode-55 Jump Game
这道题本来准备用递归加回溯的方法做,也就是每次都移动最大,看看能到哪里,如果走不通,再退回一步。这样的做法,通过了72个案例,最后一个案例超时,无法通过。于是思考了贪心的方法,判断每个地方可以到达的最远距离。将两次过程记录下来第一次,class Solution {public: bool canJump(vector& nums) { if (nums.empty())原创 2017-03-30 15:17:51 · 184 阅读 · 0 评论 -
leetcode-56 merge interval
题目如下Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18]. 首先对所有的interval进行排序,这里需要重载sort的比较操作符。其次对所有的int原创 2017-03-30 17:05:00 · 234 阅读 · 0 评论 -
leetcode-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 integer of each原创 2017-04-26 10:04:33 · 187 阅读 · 0 评论