leetcode记录
搬砖小能手lp
这个作者很懒,什么都没留下…
展开
-
【palindrome-partitioning】
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 [ ["原创 2017-09-03 17:39:03 · 286 阅读 · 0 评论 -
【reverse-linked-list-ii】
Reverse a linked list from position m ton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL, m = 2 and n = 4,return1->4->3->2->5->NULL.Note: Given m, n satisfy the f原创 2017-09-11 10:03:21 · 244 阅读 · 0 评论 -
【restore-ip-addresses】
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"]. (Order do原创 2017-09-11 09:39:06 · 251 阅读 · 0 评论 -
【sort-list】
Sort a linked list in O(n log n) time using constant space complexity.题意实现一个链表排序的算法;方法一:刚开始想的是自己定义个比较函数,然后调用sort()函数进行实现class Solution{public: static bool cmp(ListNode* a, ListNode* b)原创 2017-09-01 21:22:15 · 133 阅读 · 0 评论 -
【evaluate-reverse-polish-notation】
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another expression.Some examples: ["2", "1", "+", "3"原创 2017-09-01 15:45:41 · 207 阅读 · 0 评论 -
【Minimum Depth of Binary Tree】
题目:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.题意:求最小路径。方法一:递归class Soluti原创 2017-09-01 15:30:06 · 185 阅读 · 0 评论 -
【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-09-10 08:18:12 · 330 阅读 · 0 评论 -
【两个有序数组求中位数】
/*两个有序数组求中位数问题;这个题有很多方法:方法一:排序,找到中位数;方法二:归并排序的思想方法三:转换成求第k小值 *//*思路:使用二分查找,时间复杂度为log(m+n). 该方法的核心是将原问题转变成一个寻找第k小数的问题(假设两个原序列升序排列),这样中位数实际上是第(m+n)/2小的数。所以只要解决了第k小数的 问题,原问题也得以转载 2017-09-18 11:39:21 · 856 阅读 · 0 评论 -
【unique-binary-search-trees-ii】
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. 1 3原创 2017-09-09 13:45:56 · 554 阅读 · 0 评论 -
【insertion-sort-list】
Sort a linked list using insertion sort.题意:利用插入排序的思想实现链表排序;思路:从第二个指针开始,如果前一个指针p小于后一个指针q,则q直接连接到p后面;否则,从头查找比q大的指针,然后进行插入;class Solution{public: ListNode* insertionSortList(ListNode* h原创 2017-09-02 08:56:24 · 174 阅读 · 0 评论 -
【binary-tree-postorder-traversal】
Given a binary tree, return thepostorder traversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].Note: Recursive solution原创 2017-09-02 09:51:38 · 156 阅读 · 0 评论 -
【binary-tree-preorder-traversal】
Given a binary tree, return the preordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].Note: Recursive solution原创 2017-09-02 09:57:50 · 140 阅读 · 0 评论 -
【palindrome-partitioning-ii】
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 ="aab",Retur原创 2017-09-03 17:13:36 · 354 阅读 · 0 评论 -
【clone-graph】
Clone an undirected graph. Each node in the graph contains alabeland a list of itsneighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use#as a separator for each no原创 2017-09-03 15:10:27 · 235 阅读 · 0 评论 -
【decode-ways】
题目描述A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determin原创 2017-09-12 09:08:12 · 327 阅读 · 0 评论 -
【gas-station】
There are N gas stations along a circular route, where the amount of gas at station i isgas[i].You have a car with an unlimited gas tank and it costscost[i]of gas to travel from station i to its n原创 2017-09-03 12:13:18 · 212 阅读 · 0 评论 -
【candy】
There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least on原创 2017-09-03 10:32:18 · 201 阅读 · 0 评论 -
【single-number-ii】
Given an array of integers, every element appears three times except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without原创 2017-09-03 10:20:48 · 188 阅读 · 0 评论 -
【copy-list-with-random-pointer】
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.复杂链表的拷贝;.class Solut原创 2017-09-03 10:11:09 · 276 阅读 · 0 评论 -
【word-break-ii】
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, givens ="c原创 2017-09-03 09:58:57 · 405 阅读 · 0 评论 -
【word-break】
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, givens ="leetcode",dict =["leet",原创 2017-09-03 09:29:41 · 173 阅读 · 0 评论 -
【linked-list-cycle-ii】
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space?题意:找到循环链表的初始位置。思路:1.还是先用快慢指针方法,找出快慢指针相遇原创 2017-09-02 12:39:37 · 187 阅读 · 0 评论 -
【reorder-list】
Given a singly linked list L: L 0→L 1→…→L n-1→L n,reorder it to: L 0→L n →L 1→L n-1→L2→L n-2→…You must do this in-place without altering the nodes' values.For example,Given{1,2,3,4}, reo原创 2017-09-02 10:17:55 · 149 阅读 · 0 评论 -
【interleaving-string】
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 ="aabcc",s2 ="dbbca",When s3 ="aadbbcbcac", return true.When s3 ="aadbbbaccc", return原创 2017-09-09 10:10:07 · 329 阅读 · 0 评论 -
【validate-binary-search-tree】
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.Th原创 2017-09-09 09:51:22 · 381 阅读 · 0 评论 -
【recover-binary-search-tree】
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note: A solution using O(n ) space is pretty straight forward. Could you devis原创 2017-09-09 09:44:43 · 357 阅读 · 0 评论 -
【pascals-triangle-ii】
Given an index k, return the k th row of the Pascal's triangle.For example, given k = 3,Return[1,3,3,1].Note: Could you optimize your algorithm to use only O(k) extra space?题意:输出指定原创 2017-09-08 08:27:24 · 390 阅读 · 0 评论 -
【populating-next-right-pointers-in-each-node-ii】
Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant原创 2017-09-08 08:26:57 · 214 阅读 · 0 评论 -
【best-time-to-buy-and-sell-stock】
Say you have an array for which the i thelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),原创 2017-09-07 16:24:16 · 316 阅读 · 0 评论 -
【best-time-to-buy-and-sell-stock-ii】
Say you have an array for which the i thelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one原创 2017-09-07 16:20:47 · 319 阅读 · 0 评论 -
【best-time-to-buy-and-sell-stock-iii】
Say you have an array for which the i thelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at most twotransactions.Note: You may n原创 2017-09-07 16:13:54 · 252 阅读 · 0 评论 -
【binary-tree-maximum-path-sum】
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return6.原创 2017-09-07 15:53:33 · 209 阅读 · 0 评论 -
【valid-palindrome】
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama"is a palindrome."race a car"is not a pa原创 2017-09-07 15:41:46 · 412 阅读 · 0 评论 -
【word-ladder】
Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate word m原创 2017-09-07 15:24:05 · 292 阅读 · 0 评论 -
【n阶乘求尾数有多少个0】
题目:设计一个算法,计算出n阶乘中尾部零的个数,注意:时间负责度为o(log2)思路:要求n的阶乘,就是求1到n这个数相乘,在这1到n个数中,只有2和5相乘才会出现0,其中10的倍数也是可以看成2和5相乘的结果,所以,可以在1到n之间统计有多少个数是2的倍数以及多少个数是5的倍数就行了。很容易发现2的倍数的数一定多于5的倍数,因此可以只看n前面有多少个5就行。class Solut原创 2017-09-07 13:36:47 · 736 阅读 · 0 评论 -
【LRU Cache】
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if原创 2017-09-06 17:07:53 · 189 阅读 · 0 评论 -
【sum-root-to-leaf-numbers】
Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the number123.Find the total sum o原创 2017-09-04 10:19:57 · 327 阅读 · 0 评论 -
【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,原创 2017-09-08 08:27:40 · 235 阅读 · 0 评论 -
【distinct-subsequences】
Given a string S and a string T, count the number of distinct subsequences ofT in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none原创 2017-09-08 08:43:10 · 340 阅读 · 0 评论 -
【path-sum-ii】
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree andsum = 22, 5 / \原创 2017-09-08 08:52:01 · 239 阅读 · 0 评论