leetcode
文章平均质量分 84
zhanghuanzj
这个作者很懒,什么都没留下…
展开
-
Add Two Number
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 a link原创 2016-02-16 16:04:34 · 389 阅读 · 0 评论 -
309.Best Time to Buy and Sell Stock with Cooldown
1.基本思路:此题可通过DP来解决,但状态转移方程的构想不是那么明显,首先可以通过两个数组来表示买与卖的信息:buy[i]:表示第i天为止,最近一次股票购入后所持有的利润sell[i]:表示第i天为止,最近一次股票抛售后所持有的利润其中:最近一次表示在第i天或者之前所做的股票交易。2.状态转移方程buy[i] = max(buy[i-1],sell[i-2]-prices[i]); /原创 2016-03-14 16:36:07 · 421 阅读 · 0 评论 -
Integer to Roman
Integer to RomanGiven an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.对int值的每一位进行转换,首先建立映射表,再一一进行转换。cl原创 2016-02-29 19:47:33 · 242 阅读 · 0 评论 -
H-Index
274. H-IndexGiven an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.According to the definition of h原创 2016-02-27 20:50:44 · 276 阅读 · 0 评论 -
310. Minimum Height Trees
310. Minimum Height TreesFor a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with原创 2016-03-13 11:45:06 · 387 阅读 · 0 评论 -
Palindrome Linked List
Given a singly linked list, determine if it is a palindrome. struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}};class Solution {public: bool isP原创 2016-03-12 13:32:18 · 333 阅读 · 0 评论 -
Sqrt(x)
Sqrt(x)Implement int sqrt(int x).Compute and return the square root of x.Subscribe to see which companies asked this question求,即求的正根。更一般地,求,即求的正原创 2016-02-24 22:09:56 · 350 阅读 · 0 评论 -
Perfect Squares
279. Perfect SquaresGiven a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 becau原创 2016-02-23 20:59:18 · 344 阅读 · 0 评论 -
Increasing Triplet Subsequence
334.Increasing Triplet SubsequenceGiven an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should:Return true if th原创 2016-02-22 20:48:26 · 319 阅读 · 0 评论 -
Convert Sorted List to Binary Search Tree
Convert Sorted List to Binary Search TreeGiven a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.用递归的方法:原创 2016-03-07 21:10:47 · 321 阅读 · 0 评论 -
Add Binary
Add BinaryGiven two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".代码:class Solution {public: s原创 2016-03-06 20:54:46 · 248 阅读 · 0 评论 -
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, and there exists one unique longest palindromic substring.Manacher算法计算最长回文原创 2016-02-16 16:32:19 · 319 阅读 · 0 评论 -
Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 52 -> AZ原创 2016-02-16 16:41:26 · 357 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.For example:1.The longest substring without repeating letters for "abcabcbb" is "abc", which the length is原创 2016-02-16 16:08:35 · 363 阅读 · 0 评论 -
227. Basic Calculator II
常用方法为两个栈,数值栈与操作符栈,每次操作符入栈前比较优先级,小的推迟运算。以下是不用栈的方法, class Solution { public: int calculate(string s) { istringstream is('+'+s+'+'); char op; int result=0,n,prevalue=0;原创 2016-03-15 13:05:39 · 312 阅读 · 0 评论