摘要:
Feb 15 '12Given 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./*** De 阅读全文
摘要:
Jun 25 '12Given a collection of integers that might contain duplicates,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For example,IfS=[1,2,2], a solution is:[ [2], [1], [1,2,2], [2,2], [1,2], []... 阅读全文
摘要:
4.findoutpythagoreantripletsinanintegerarray.#include <iostream>
#include <vector>
#include <set>
#include <cmath>
using namespace std; vector<vector<int> > findP( vector<int> & x ) { set<int> pool; vector<vector<int> > rel; if(x.size() 阅读全文
摘要:
integersofsymmetricdigitscoplexity: O(n)#include <iostream>
#include <vector> using namespace std; bool isSymetric( int x ) { char buff[32]; int i=0; while( x != 0){ buff[i++] = x%10; x/=10; } int j=0; i-=1; while( j<i) { if(buff[j++] != buff[i--] ) return false; } return true;
} ... 阅读全文