2013年8月29日

摘要: 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) 编辑

2013年8月22日

摘要: Distinct SubsequencesGiven a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining character 阅读全文
posted @ 2013-08-22 19:12 似溦若岚 阅读(215) 评论(0) 推荐(0) 编辑
摘要: Merge k Sorted ListsMergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.嗯……没啥好说的…… 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(NULL) {} 7 * }; 8 *... 阅读全文
posted @ 2013-08-22 19:10 似溦若岚 阅读(134) 评论(0) 推荐(0) 编辑
摘要: TriangleGiven 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,5,7], [4,1,8,3]]The minimum path sum from top to bottom is11(i.e.,2+3+5+1= 11).Note:Bonus point if y... 阅读全文
posted @ 2013-08-22 08:24 似溦若岚 阅读(161) 评论(0) 推荐(0) 编辑

2013年8月21日

摘要: Edit DistanceGiven two wordsword1andword2, find the minimum number of steps required to convertword1toword2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:a) Insert a characterb) Delete a characterc) Replace a characterDP特训第一弹~某种情况下的最小路径,就是分别增、删、改所产生结果 阅读全文
posted @ 2013-08-21 22:08 似溦若岚 阅读(155) 评论(0) 推荐(0) 编辑

导航