摘要: 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 be 阅读全文
posted @ 2013-08-15 15:09 懒猫欣 阅读(210) 评论(0) 推荐(0)
摘要: Given 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 =2, and A is 阅读全文
posted @ 2013-08-15 14:56 懒猫欣 阅读(154) 评论(0) 推荐(0)
摘要: class Solution {public: double pow(double x, int n) { if(n==1)return x; else if(n==-1)return 1/x; else if(n==0)return 1; else{ bool flag=n>0; if(!flag)n=-n; double ret=1; int bit=0x40000000; for(int i=0;i<31;i+... 阅读全文
posted @ 2013-08-15 13:53 懒猫欣 阅读(164) 评论(2) 推荐(0)