LeetCode
文章平均质量分 58
Queen、
这个作者很懒,什么都没留下…
展开
-
LeetCode 242. Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may ass原创 2017-09-23 21:37:10 · 220 阅读 · 0 评论 -
LeetCode 55. 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.Determine if yo原创 2017-09-17 21:48:16 · 217 阅读 · 0 评论 -
LeetCode 54. 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 ]]You原创 2017-09-17 21:47:00 · 245 阅读 · 0 评论 -
LeetCode 48. Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify the input 2D matrix d原创 2017-09-17 21:42:22 · 198 阅读 · 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 the combinati原创 2017-09-17 21:37:59 · 287 阅读 · 0 评论 -
LeetCode 39. Combination Sum
Given a set of candidate numbers (C) (without duplicates) 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 fr原创 2017-09-17 21:32:01 · 196 阅读 · 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 targ原创 2017-09-17 21:29:46 · 214 阅读 · 0 评论 -
LeetCode 11. Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin原创 2017-09-17 21:25:51 · 188 阅读 · 0 评论 -
LeetCode 90. Subsets II
Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,2], a solutio原创 2017-09-18 22:07:34 · 393 阅读 · 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 first five原创 2017-09-18 22:05:15 · 356 阅读 · 0 评论 -
LeetCode 237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2017-09-28 20:25:32 · 224 阅读 · 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 l原创 2017-09-28 22:11:17 · 242 阅读 · 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.分析:旋转链表,新链表的头节点应该是len-k%len原创 2017-10-02 22:11:50 · 238 阅读 · 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;原创 2017-09-17 21:53:26 · 215 阅读 · 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 ], [原创 2017-09-17 21:56:28 · 344 阅读 · 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-09-17 21:57:22 · 308 阅读 · 0 评论 -
LeetCode 290. Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.原创 2017-09-23 22:15:19 · 265 阅读 · 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.分析:题目的意思将将两个已排序的链表合并成一个链表定义一个链表头指针和连接指针。连接指针用原创 2017-09-25 19:28:48 · 245 阅读 · 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.分析:题目大意为将给定的已排序好的原创 2017-09-25 20:28:47 · 272 阅读 · 0 评论 -
LeetCode 238. Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O(n原创 2017-09-18 21:25:38 · 400 阅读 · 0 评论 -
LeetCode 78. Subsets
Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3], a solution is:[ [3], [1], [原创 2017-09-17 22:13:18 · 267 阅读 · 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 integers原创 2017-09-17 22:11:58 · 232 阅读 · 0 评论 -
LeetCode 209. Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the原创 2017-09-18 21:32:23 · 438 阅读 · 0 评论 -
LeetCode 228. Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges.Example 1:Input: [0,1,2,4,5,7]Output: ["0->2","4->5","7"]Example 2:Input: [0,2,3,4,6,8,9]Output原创 2017-09-18 21:40:31 · 411 阅读 · 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 r原创 2017-09-17 22:07:59 · 223 阅读 · 0 评论 -
LeetCode 216. Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Example 1:Inpu原创 2017-09-18 21:52:41 · 403 阅读 · 0 评论 -
LeetCode 79. Word Search
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 vertically n原创 2017-09-18 21:59:07 · 393 阅读 · 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-09-17 22:04:30 · 220 阅读 · 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-09-17 21:59:30 · 218 阅读 · 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 m原创 2017-10-02 22:19:40 · 255 阅读 · 0 评论