C++
文章平均质量分 56
细雨逐光
这个作者很懒,什么都没留下…
展开
-
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
023 Merge k Sorted Lists [Leetcode]
题目内容: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.题目分析: k个排过序的链表,要将它们合并起来就要求能够在较短的时间内将当前的k个数进行排序,并且能够高效得支持数字的增删操作。 可以使用的方法有:败者树,堆排序,这两个算法在插入、删原创 2015-10-27 19:07:34 · 389 阅读 · 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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
139 Word Break [Leetcode]
题目内容: Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, given s = “leetcode”, d原创 2015-10-04 15:38:45 · 254 阅读 · 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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
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 评论 -
093 Restore IP Addresses [Leetcode]
题目内容: Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example: Given “25525511135”, return [“255.255.11.135”, “255.255.111.35”原创 2015-09-04 11:22:48 · 286 阅读 · 0 评论 -
095 Unique Binary Search Trees II [Leetcode]
题目内容: Given n, generate all structurally unique BST’s (binary search trees) that store values 1…n. For example, Given n = 3, your program should return all 5 unique BST’s shown below.和上一题一样,递归构原创 2015-09-04 19:09:01 · 259 阅读 · 0 评论 -
133 Clone Graph [Leetcode]
题目内容: Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ’s undirected graph serialization: Nodes are labeled uniquely. We use # as a sepa原创 2015-10-03 23:08:26 · 256 阅读 · 0 评论 -
132 Palindrome Partitioning II [Leetcode]
题目内容: Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s. For example, given s = “aa原创 2015-10-03 23:56:30 · 306 阅读 · 0 评论 -
131 Palindrome Partitioning [Leetcode]
题目内容: Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For example, given s = “aab”, Return [原创 2015-10-02 23:02:41 · 291 阅读 · 0 评论 -
130 Surrounded Regions [Leetcode]
题目内容: Given a 2D board containing ‘X’ and ‘O’, capture all regions surrounded by ‘X’. A region is captured by flipping all ‘O’s into ‘X’s in that surrounded region.For example,X X X XX O O XX原创 2015-10-02 20:45:11 · 360 阅读 · 0 评论 -
127 Word Ladder [Leetcode]
题目内容: Given two words (beginWord and endWord), and a dictionary’s word list, find the length of shortest transformation sequence from beginWord to endWord, such that: Only one letter can be c原创 2015-09-27 09:10:23 · 298 阅读 · 0 评论 -
124 Binary Tree Maximum Path Sum [Leetcode]
题目内容: Given a binary tree, find the maximum path sum. For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connecti原创 2015-09-27 09:31:43 · 246 阅读 · 0 评论