
leetcode
寻路人davey
Deep Learning/图像处理
展开
-
Leetcode--14. Longest Common Prefix
Leetcode–14. Longest Common Prefix本题比较简单,对字符串进行纵向扫描即可,从位置0开始,直到遇到一个不匹配。注意考虑字符串为空的情况,否则不能AC。C++代码如下:string longestCommonPrefix(vector<string>& strs) { if(strs.empty()) return "";原创 2017-04-11 19:21:15 · 308 阅读 · 0 评论 -
LeetCode -- 121. Best Time to Buy and Sell Stock
题目:Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),原创 2017-05-25 17:02:00 · 303 阅读 · 0 评论 -
Leetcode -- 36. Valid Sudoku
题目:Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’. A partially filled sud原创 2017-04-24 21:42:21 · 241 阅读 · 0 评论 -
LeetCode -- 122. Best Time to Buy and Sell Stock II
题目:Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on原创 2017-05-26 09:26:24 · 268 阅读 · 0 评论 -
LeetCode -- 5. Longest Palindromic Substring
题目:Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.Example:Inp原创 2017-05-16 22:49:14 · 224 阅读 · 0 评论 -
LeetCode -- 53. 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,-1,2,1] has t原创 2017-05-16 23:37:53 · 249 阅读 · 0 评论 -
LeetCode -- 63. Unique Paths II
题目:Follow up for “Unique Paths”: Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space is marked as 1 and 0 respectively in the grid原创 2017-05-17 10:21:01 · 228 阅读 · 0 评论 -
LeetCode -- 62. Unique Paths
题目:A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the原创 2017-05-17 09:41:31 · 353 阅读 · 0 评论 -
LeetCode -- 64. Minimum Path Sum
题目:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at a原创 2017-05-17 11:00:03 · 246 阅读 · 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?Note: Given n will be a positive原创 2017-05-17 11:15:14 · 274 阅读 · 0 评论 -
LeetCode -- 96. Unique Binary Search Trees
题目:Given n, how many structurally unique BST’s (binary search trees) that store values 1…n?For example, Given n = 3, there are a total of 5 unique BST’s. 1 3 3 2 1 \原创 2017-05-17 23:20:26 · 220 阅读 · 0 评论 -
LeetCode -- Range Sum Query - Immutable
题目:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRange(0, 5) -> -3No原创 2017-08-01 10:54:16 · 203 阅读 · 0 评论 -
LeetCode -- 198. House Robber
题目:You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent hou原创 2017-08-01 16:28:47 · 333 阅读 · 0 评论 -
LeetCode -- 213. House Robber II
题目:After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time, all houses at this place are arranged in a原创 2017-08-01 17:40:25 · 290 阅读 · 0 评论 -
LeetCode -- 650. 2 Keys Keyboard
题目:Initially on a notepad only one character ‘A’ is present. You can perform two operations on this notepad for each step:Copy All: You can copy all the characters present on the notepad (partial copy原创 2017-08-02 11:49:22 · 1825 阅读 · 0 评论 -
LeetCode -- 66. Plus One
题目:Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. You may assume the integer do not contain any leading zero, except the number 0 itself. The digits原创 2017-07-25 23:42:54 · 243 阅读 · 0 评论 -
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 hold additio原创 2017-07-26 21:15:06 · 241 阅读 · 0 评论 -
LeetCode -- 120. Triangle
题目:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5,7]原创 2017-05-25 16:12:31 · 287 阅读 · 0 评论 -
Leetcode -- 491. Increasing Subsequences
题目:Given an integer array, your task is to find all the different possible increasing subsequences of the given array, and the length of an increasing subsequence should be at least 2 . Example:Input:原创 2017-05-11 23:25:11 · 402 阅读 · 0 评论 -
Leetcode--16. 3Sum Closest
题目:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact原创 2017-04-11 20:35:05 · 214 阅读 · 0 评论 -
Leetcode--17. Letter Combinations of a Phone Number
题目:Given 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.Input:Digit string “2原创 2017-04-12 09:21:51 · 256 阅读 · 0 评论 -
Leetcode -- 22. Generate Parentheses
题目:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "()(())",原创 2017-04-18 09:33:53 · 223 阅读 · 0 评论 -
Leetcode--19. Remove Nth Node From End of List
题目:Given a linked list, remove the nth node from the end of list and return its head.For example,Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the linked list原创 2017-04-14 21:41:26 · 268 阅读 · 0 评论 -
Leetcode -- 20. Valid Parentheses
题目:Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the correct order, “()” and “()[]{}” are all valid bu原创 2017-04-16 23:22:04 · 233 阅读 · 0 评论 -
Leetcode -- 21. Merge Two Sorted Lists
题目:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.思路: 本题考查基础的链表操作。因为两个链表l1和l2已经有序,所以只需要按顺序比较即可,把较小的结点插入到新的原创 2017-04-16 23:46:51 · 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 read off as “one 2原创 2017-05-10 23:54:02 · 277 阅读 · 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 place with c原创 2017-04-21 00:03:20 · 233 阅读 · 0 评论 -
Leetcode -- 27. Remove Element
题目:Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.The or原创 2017-04-21 00:25:43 · 191 阅读 · 0 评论 -
Leetcode -- 28. Implement strStr()
题目:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.思路:本题是让找到一个字符串是不是另一个字符串的子串,如果是就返回下标,如果不是返回-1。暴力比较,时间复杂度:O(mn)。C++代码如下:int原创 2017-04-21 08:52:01 · 266 阅读 · 0 评论 -
Leetcode -- 29. Divide Two Integers
题目:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.思路:不用乘法,除法和取模运算实现两个数的除法。注意考虑边界,如果divisor = -1, dividend = INT_MIN这时候会产生溢出,直接返回INT_MAX。原创 2017-04-21 09:46:21 · 214 阅读 · 0 评论 -
Leetcode -- 31. 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 possible o原创 2017-04-21 15:52:30 · 213 阅读 · 0 评论 -
Leetcode -- 33. Search in Rotated Sorted Array
题目:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the原创 2017-04-21 17:53:52 · 239 阅读 · 0 评论 -
Leetcode -- 34. Search for a Range
题目:Given an array of integers sorted in ascending order, 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原创 2017-04-21 19:56:51 · 374 阅读 · 0 评论 -
Leetcode -- 24. Swap Nodes in Pairs
题目:Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You may n原创 2017-04-20 23:29:47 · 227 阅读 · 0 评论 -
Leetcode -- 35. Search Insert Position
题目:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array.原创 2017-04-22 14:17:16 · 578 阅读 · 0 评论 -
LeetCode -- 118. Pascal's Triangle
题目:Given numRows, generate the first numRows of Pascal’s triangle. For example, given numRows = 5, Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]思路: 本题主要考查vector 的基本操作,杨辉三角形的计算原创 2017-07-26 21:53:53 · 243 阅读 · 0 评论