leetcode
文章平均质量分 62
onlyou2030
内心仰望理想的人都在埋头苦干!
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
leetcode 88:Merge Sorted Array
题目:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hol原创 2015-12-02 23:02:20 · 475 阅读 · 0 评论 -
leetcode 66:Add Binary
题目:Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".string addBinary(string a, string b) { string result = ""; i原创 2015-11-19 22:00:57 · 473 阅读 · 0 评论 -
leetcode 65:Plus One
题目:Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.思路:这题比较简单原创 2015-11-19 21:33:54 · 319 阅读 · 0 评论 -
leetcode 60:Permutation Sequence
题目:The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""213"原创 2015-11-18 21:33:23 · 350 阅读 · 0 评论 -
leetcode 56:Merge Intervals
题目: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].struct Interval { int start; int end; In原创 2015-11-18 19:27:35 · 337 阅读 · 0 评论 -
leetcode 57:Insert Interval
题目:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start ti原创 2015-11-18 20:31:36 · 459 阅读 · 0 评论 -
leetcode 58:Length of Last Word
题目:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A原创 2015-11-18 20:49:43 · 304 阅读 · 0 评论 -
leetcode 69:
题目:Implement int sqrt(int x).Compute and return the square root of x.思路:用二分法,比较简单时间复杂度:O(lgn)class Solution {public: int sqrt(int x) { if (0 == x) return 0;原创 2015-11-23 19:29:04 · 302 阅读 · 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原创 2015-11-18 21:15:57 · 351 阅读 · 0 评论 -
leetcode 54:Jump Game
题目:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.De原创 2015-11-16 23:00:58 · 284 阅读 · 0 评论 -
leetcode 53:Spiral Matrix
题目:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9原创 2015-11-16 21:39:14 · 329 阅读 · 0 评论 -
leetcode 52:Maximum Subarray
题目:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−原创 2015-11-16 20:59:19 · 346 阅读 · 0 评论 -
leetcode 50:Pow(x, n)
题目:Implement pow(x, n).思路:这题考的是用最短的时间来求幂次方。如果我们用for循环来做,则要做n次乘法,时间复杂度为O(n);如果我们用二分法来做,即先求pow(x,n/2),在将结果相乘,这样只需分lg(n)次,每次做2次或者3次乘法,时间复杂度为O(lgn)。注意边界条件,n可以为负值。实现如下:class Solution {pu原创 2015-11-16 19:52:15 · 374 阅读 · 0 评论 -
leetcode 70:Climbing Stairs
题目:You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?思路:这题和前面Unique Path原创 2015-11-24 19:06:19 · 265 阅读 · 0 评论 -
leetcode 72:Edit Distance
题目:Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitt原创 2015-11-24 20:18:27 · 269 阅读 · 0 评论 -
leetcode 61:Rotate List
题目:Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.思路:这题可以先确定链表数,然后找到需要截断的结原创 2015-11-19 19:47:11 · 293 阅读 · 0 评论 -
leetcode 86:Partition List
题目:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes i原创 2015-12-02 13:02:38 · 420 阅读 · 0 评论 -
leetcode 87:Scramble String
题目:Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great /原创 2015-12-02 14:13:13 · 520 阅读 · 0 评论 -
leetcode 81:Search in Rotated Sorted Array II
题目:Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target原创 2015-11-29 20:41:42 · 393 阅读 · 0 评论 -
leetcode 83:Remove Duplicates from Sorted List
题目:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.思路:这题很简单,直接上代码原创 2015-11-30 21:00:02 · 314 阅读 · 0 评论 -
leetcode 82:Remove Duplicates from Sorted List II
题目:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Gi原创 2015-11-30 20:49:33 · 337 阅读 · 0 评论 -
leetcode 80:Remove Duplicates from Sorted Array II
题目:Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the f原创 2015-11-29 15:56:25 · 317 阅读 · 0 评论 -
leetcode 79:Word Search(redo)
题目:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or v原创 2015-11-29 13:20:27 · 315 阅读 · 0 评论 -
leetcode 78:Subsets
题目:Given a set of distinct integers, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.原创 2015-11-27 23:08:28 · 321 阅读 · 0 评论 -
leetcode 77:Combinations
题目:Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3],原创 2015-11-27 22:45:32 · 319 阅读 · 0 评论 -
leetcode 76:Minimum Window Substring
题目:Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum windo原创 2015-11-26 22:39:31 · 347 阅读 · 0 评论 -
leetcode 75:Sort Colors
题目:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the原创 2015-11-26 21:38:32 · 266 阅读 · 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 intege原创 2015-11-26 20:57:08 · 385 阅读 · 0 评论 -
leetcode 29:Divide Two Integers
题目:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.class Solution {public: int divide(int dividend, int divisor) {原创 2015-10-13 16:49:32 · 323 阅读 · 0 评论 -
leetcode 26:Remove Duplicates from Sorted Array
题目:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in p原创 2015-10-12 15:46:38 · 268 阅读 · 0 评论 -
leetcode 43:Multiply Strings
题目:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.原创 2015-11-04 20:25:42 · 344 阅读 · 0 评论 -
leetcode 17:Letter Combinations of a Phone Number(15-10-5)
1.ProblemGiven a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.I原创 2015-10-05 19:35:14 · 395 阅读 · 0 评论 -
leetcode 42:Trapping Rain Water
题目: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,1,3原创 2015-11-04 19:40:18 · 289 阅读 · 0 评论 -
leetcode 39:Combination Sum
题目:Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlim原创 2015-10-18 17:04:36 · 305 阅读 · 0 评论 -
leetcode 41:First Missing Positive
题目: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 uses原创 2015-11-04 16:52:21 · 311 阅读 · 0 评论 -
leetcode 40:Combination Sum II
题目:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in th原创 2015-11-04 16:03:04 · 308 阅读 · 0 评论 -
leetcode 37:Sudoku Solver
题目:Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.原创 2015-10-18 16:37:10 · 258 阅读 · 0 评论 -
leetcode 38:Count and Say
题目:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is rea原创 2015-10-18 16:42:27 · 307 阅读 · 0 评论 -
leetcode 34:
题目:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is n原创 2015-10-17 20:40:24 · 346 阅读 · 0 评论 -
leetcode31:Next Permutation
题目:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest原创 2015-10-16 14:07:07 · 395 阅读 · 0 评论
分享