摘要: Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, return1->2->3./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val 阅读全文
posted @ 2013-01-15 12:44 西施豆腐渣 阅读(153) 评论(0) 推荐(0) 编辑
摘要: Follow up for "Remove Duplicates":What if duplicates are allowed at mosttwice?For example,Given sorted array A =[1,1,1,2,2,3],Your function should return length =5, and A is now[1,1,2,2,3].class Solution { public: int removeDuplicates(int A[], int n) { // Start typing your C/C++ solution.. 阅读全文
posted @ 2013-01-15 07:27 西施豆腐渣 阅读(109) 评论(0) 推荐(0) 编辑
摘要: Feb 16 '12Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.For example,Given input array A =[1,1,2],Your function should return length 阅读全文
posted @ 2013-01-15 05:45 西施豆腐渣 阅读(130) 评论(0) 推荐(0) 编辑
摘要: Implement pow(x,n).class Solution { public: double pow(double x, int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if( n==0) return 1; if( n==1) return x; bool sign = n>0 ? true : false; if(!si... 阅读全文
posted @ 2013-01-15 05:04 西施豆腐渣 阅读(182) 评论(0) 推荐(0) 编辑
摘要: Given a number represented as an array of digits, plus one to the number.class Solution { public: vector<int> plusOne(vector<int> &digits) { // Start typing your C/C++ solution below // DO NOT write int main() function vector<int> rel( digits.size() ); in... 阅读全文
posted @ 2013-01-15 04:27 西施豆腐渣 阅读(115) 评论(0) 推荐(0) 编辑