2013年8月29日

摘要: Word LadderGiven two words (startandend), and a dictionary, find the length of shortest transformation sequence fromstarttoend, such that:Only one letter can be changed at a timeEach intermediate word must exist in the dictionaryFor example,Given:start="hit"end="cog"dict=["h 阅读全文
posted @ 2013-08-29 22:22 似溦若岚 阅读(230) 评论(0) 推荐(0) 编辑
摘要: Valid PalindromeGiven 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"isnota palindrome.Note:Have you consider that the string might be empty? This is a 阅读全文
posted @ 2013-08-29 10:30 似溦若岚 阅读(181) 评论(0) 推荐(0) 编辑
摘要: Binary Tree Maximum Path SumGiven 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.二叉树后序历遍的变形。 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * ... 阅读全文
posted @ 2013-08-29 10:06 似溦若岚 阅读(174) 评论(0) 推荐(0) 编辑
摘要: Reverse IntegerReverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321做大水题有益于身心健康…… 1 class Solution { 2 public: 3 int reverse(int x) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 int sign = 1, tens =... 阅读全文
posted @ 2013-08-29 09:20 似溦若岚 阅读(150) 评论(0) 推荐(0) 编辑
摘要: Sqrt(x)Implementint sqrt(int x).Compute and return the square root ofx.二分,鉴于返回值要int,精度搞到0.1即可…… 1 class Solution { 2 public: 3 4 inline double dabs(double d) { 5 return d > 0 ? d : -d; 6 } 7 8 int sqrt(int x) { 9 // Start typing your C/C++ solution below10 /... 阅读全文
posted @ 2013-08-29 08:59 似溦若岚 阅读(135) 评论(0) 推荐(0) 编辑
摘要: Best Time to Buy and Sell Stock IIISay you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at mosttwotransactions.Note:You may not engage in multiple transactions at the same time (ie, you must sell the stoc 阅读全文
posted @ 2013-08-29 08:43 似溦若岚 阅读(166) 评论(0) 推荐(0) 编辑
摘要: Best Time to Buy and Sell Stock IISay you have an array for which theithelement 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 and sell one share of the stock multiple times). However, you may not e 阅读全文
posted @ 2013-08-29 08:42 似溦若岚 阅读(130) 评论(0) 推荐(0) 编辑
摘要: Best Time to Buy and Sell StockSay you have an array for which theithelement 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), design an algorithm to find the maximum profit.很水,没什么好说的。 1 class Solution 阅读全文
posted @ 2013-08-29 08:39 似溦若岚 阅读(151) 评论(0) 推荐(0) 编辑
摘要: Swap Nodes in PairsGiven a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algorithm should use only constant space. You maynotmodify the values in the list, only nodes itself can be changed.嗯, 阅读全文
posted @ 2013-08-29 08:37 似溦若岚 阅读(112) 评论(0) 推荐(0) 编辑

导航