leetcode
文章平均质量分 51
细雨逐光
这个作者很懒,什么都没留下…
展开
-
153 Find Minimum in Rotated Sorted Array [Leetcode]
题目内容: Suppose a sorted array 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). Find the minimum element. You may assume no duplicate原创 2015-10-28 14:44:07 · 288 阅读 · 0 评论 -
006 ZigZag Conversion [Leetcode]
题目内容: The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N原创 2015-11-11 16:27:23 · 376 阅读 · 0 评论 -
004 Median of Two Sorted Arrays [Leetcode]
题目内容: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).解题思路:原创 2015-11-11 13:42:10 · 452 阅读 · 1 评论 -
005 Longest Palindromic Substring [Leetcode]
题目内容: Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.解题思路: 比较直观的方法,就是以原创 2015-11-11 15:19:20 · 324 阅读 · 0 评论 -
003 Longest Substring Without Repeating Characters [Leetcode]
题目内容: Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is原创 2015-11-09 14:45:38 · 323 阅读 · 0 评论 -
002 Add Two Numbers [Leetcode]
题目内容: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as原创 2015-11-09 14:39:10 · 349 阅读 · 0 评论 -
001 Two Sum [Leetcode]
题目内容: Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the ta原创 2015-11-09 14:32:30 · 338 阅读 · 0 评论 -
121 Best Time to Buy and Sell Stock [Leetcode]
题目内容: 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 th原创 2015-09-21 07:16:00 · 261 阅读 · 0 评论 -
122 Best Time to Buy and Sell Stock II [Leetcode]
题目内容: 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 (i原创 2015-09-21 07:20:57 · 237 阅读 · 0 评论 -
212 Word Search II [Leetcode]
题目内容: Given a 2D board and a list of words from the dictionary, find all words in the board. Each word must be constructed from letters of sequentially adjacent cell, where “adjacent” cells are原创 2015-10-06 17:03:44 · 594 阅读 · 0 评论 -
142 Linked List Cycle II [Leetcode]
题目内容: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note: Do not modify the linked list. Follow up: Can you solve it without using extra原创 2015-10-07 10:21:48 · 392 阅读 · 0 评论 -
134 Gas Station [Leetcode]
题目内容: There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from statio原创 2015-10-06 14:50:22 · 365 阅读 · 0 评论 -
007 Reverse Integer [Leetcode]
题目内容: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321click to show spoilers. Have you thought about this? Here are some good questions to ask原创 2015-11-11 16:31:47 · 388 阅读 · 0 评论 -
008 String to Integer (atoi) [Leetcode]
题目内容: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible原创 2015-11-11 16:35:42 · 389 阅读 · 0 评论 -
009 Palindrome Number [Leetcode]
题目内容: Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Some hints: Could negative integers be palindromes? (ie, -1) If you are thin原创 2015-11-11 16:41:28 · 449 阅读 · 0 评论 -
123 Best Time to Buy and Sell Stock III [Leetcode]
题目内容: 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 at most two transactions. Note原创 2015-09-21 07:32:04 · 383 阅读 · 0 评论 -
154 Find Minimum in Rotated Sorted Array II [Leetcode]
题目内容: Follow up for “Find Minimum in Rotated Sorted Array”: What if duplicates are allowed? Would this affect the run-time complexity? How and why? Suppose a sorted array is rotated at s原创 2015-10-28 15:24:56 · 382 阅读 · 0 评论 -
206 Reverse Linked List [Leetcode]
题目内容: Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursively. Could you implement both?解题思路之前提到过,直接贴代码: 迭代解法:/** * Definition for singly-linked原创 2015-10-28 00:40:18 · 310 阅读 · 0 评论 -
061 Rotate List [Leetcode]
题目内容: 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.思路: 使用双指针。注意处理k比链表长度还要原创 2015-10-27 20:48:43 · 310 阅读 · 0 评论 -
109 Convert Sorted List to Binary Search Tree [Leetcode]
题目内容: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.思路: 只要知道了链表的中间节点,就可以把问题分解为子问题,中间节点是当前的根节点,左边的排序链表构成左子树,右边的构成右子树。 用了两种方法 1. 一种是将节原创 2015-10-27 21:31:05 · 412 阅读 · 0 评论 -
148 Sort List [Leetcode]
题目内容: Sort a linked list in O(n log n) time using constant space complexity.根据给出的时间复杂度,可以想到满足的排序方法有: 1. 快速排序 2. 堆排序 3. 归并排序再考虑空间复杂度: 1. 快速排序主要要实现partition算法,在数组中它实现的算法复杂度为O(n),利用链表,同样可以在O(n)时间内实原创 2015-10-28 00:10:37 · 363 阅读 · 0 评论 -
143 Reorder List [Leetcode]
题目内容: Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do this in-place without altering the nodes’ values. For example, Given {1,2,3,4},原创 2015-10-27 23:49:41 · 372 阅读 · 0 评论 -
025 Reverse Nodes in k-Group [Leetcode]
题目内容: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain原创 2015-10-27 20:29:18 · 348 阅读 · 0 评论 -
024 Swap Nodes in Pairs [Leetcode]
题目内容: 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 cons原创 2015-10-27 19:11:49 · 331 阅读 · 0 评论 -
082&083 Remove Duplicates from Sorted List I II [Leetcode]
题目内容: 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-10-27 20:53:16 · 274 阅读 · 0 评论 -
138 Copy List with Random Pointer [Leetcode]
题目内容: A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list.解题思路: 最优方法时间复杂度为O(n)且不需原创 2015-10-27 21:42:02 · 503 阅读 · 0 评论 -
216 Combination Sum III [Leetcode]
题目内容: 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. Ensure that n原创 2015-10-06 17:39:07 · 350 阅读 · 0 评论 -
140 Word Break II [Leetcode]
题目内容: Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example原创 2015-10-06 11:43:25 · 366 阅读 · 0 评论 -
086 Partition List [Leetcode]
题目内容: 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-08-16 23:16:14 · 269 阅读 · 0 评论 -
085 Maximal Rectangle [Leetcode]
题目内容: Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing all ones and return its area.DP的过程还没有想清楚,先利用上一题的结果可以解决该问题。统计每一行为止向上有多少个连续的1做为bar的高度,对每一行调用Largest Rectan原创 2015-08-16 22:14:49 · 246 阅读 · 0 评论 -
033 Search in Rotated Sorted Array[Leetcode]
题目描述 Suppose a sorted array 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原创 2015-08-03 23:55:45 · 348 阅读 · 0 评论 -
084 Largest Rectangle in Histogram [Leetcode]
题目描述: Given n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histogram原创 2015-08-16 17:45:35 · 507 阅读 · 0 评论 -
079 Word Search[Leetcode]
题目描述 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原创 2015-08-02 12:25:41 · 411 阅读 · 0 评论 -
090 Subsets II [Leetcode]
题目内容: Given a collection of integers that might contain duplicates, nums, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not conta原创 2015-08-28 20:34:11 · 334 阅读 · 0 评论 -
078 Subsets [Leetcode]
题目内容: 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. For ex原创 2015-08-27 01:10:06 · 317 阅读 · 0 评论 -
087 Scramble String [Leetcode]
题目内容: 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-08-27 00:58:29 · 420 阅读 · 0 评论 -
089 Grey Code [Leetcode]
题目内容: The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the seq原创 2015-08-26 00:24:40 · 443 阅读 · 0 评论 -
082 Remove Duplicates from Sorted List II [Leetcode]
题目内容: 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.原创 2015-08-09 21:48:55 · 242 阅读 · 0 评论 -
083 Remove Duplicates from Sorted List [Leetcode]
题目内容: 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-08-09 22:03:35 · 291 阅读 · 0 评论 -
088 Merge Sorted Array [Leetcode]
题目内容: 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 ho原创 2015-08-18 23:27:53 · 243 阅读 · 0 评论