2014年3月24日

Sort List

摘要: Sort a linked list inO(nlogn) time using constant space complexity.逻辑正确,尾指针没有置空,调了好久……/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *sortList(ListNode *head) {... 阅读全文

posted @ 2014-03-24 22:04 pengyu2003 阅读(135) 评论(0) 推荐(0) 编辑

Evaluate Reverse Polish Notation

摘要: Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another expression.Some examples: ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9 ["4", "13&qu 阅读全文

posted @ 2014-03-24 16:33 pengyu2003 阅读(102) 评论(0) 推荐(0) 编辑

Reverse Words in a String

摘要: Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".click to show clarification.Clarification:What constitutes a word?A sequence of non-space characters constitutes a word.Could the input string contain leading o 阅读全文

posted @ 2014-03-24 16:14 pengyu2003 阅读(131) 评论(0) 推荐(0) 编辑

Sqrt(x)

摘要: Implementint sqrt(int x).Compute and return the square root ofx.此题看着简单,实则坑爹啊!!!!!首先,关于平方,int是不够用的。其次,二分法肯定好用,但是,最终的结果怎么取?原则上取小于等于的最近整数。但是mid的计算可能会更改这个数,所以需要调整一下。class Solution {public: int sqrt(int x) { long long left = 0; long long right = x; long long mid = left + (right - lef... 阅读全文

posted @ 2014-03-24 15:27 pengyu2003 阅读(126) 评论(0) 推荐(0) 编辑

Permutations II

摘要: Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2]have the following unique permutations:[1,1,2],[1,2,1], and[2,1,1].class Solution {public: vector > re; vector > permuteUnique(vector &num) { map m; int size = ... 阅读全文

posted @ 2014-03-24 14:00 pengyu2003 阅读(104) 评论(0) 推荐(0) 编辑

导航