上一页 1 2 3 4 5 6 7 ··· 20 下一页
摘要: void connect(TreeLinkNode *root) { // Note: The Solution object is instantiated only once and is reused by each test case. if(!root) return; TreeLinkNode* first,*cur; first = cur = root; while(cur) { if(cur->left) { ... 阅读全文
posted @ 2013-10-23 14:47 summer_zhou 阅读(169) 评论(0) 推荐(0)
摘要: vector getRow(int rowIndex) { // Note: The Solution object is instantiated only once and is reused by each test case. if(rowIndex(); vector res(rowIndex+1); res[0] = 1; for(int i=1;i0;j--) res[j] += res[j-1]; res[0] = 1; ... 阅读全文
posted @ 2013-10-23 14:30 summer_zhou 阅读(134) 评论(0) 推荐(0)
摘要: //注意容器的空间,如果没有预设好,[]访问会出错的。。。。---这个很容易出问题。 vector > generate(int numRows) { // Note: The Solution object is instantiated only once and is reused by each test case. vector> res; if(numRows()); res[0].push_back(1); for(int i=1;i<numRows;i++) { ... 阅读全文
posted @ 2013-10-23 11:50 summer_zhou 阅读(140) 评论(0) 推荐(0)
摘要: ListNode *deleteDuplicates(ListNode *head) { // Note: The Solution object is instantiated only once and is reused by each test case. if(head==NULL) return NULL; ListNode* prev = head,*cur = head->next; while(cur) { ListNode* next =... 阅读全文
posted @ 2013-10-22 23:06 summer_zhou 阅读(127) 评论(0) 推荐(0)
摘要: DP。O(n)的空间复杂度。时间复杂度O(n^2)sum[i][j] = min(sum[i-1][j-1],sum[i-1][j])+triangle[i][j]; //所该式可以看出,可以用O(n)的额外空间。求解的时候,记得从大往小求。 int minimumTotal(vector > &triangle) { // Note: The Solution object is instantiated only once and is reused by each test case. if(triangle.empty()) re... 阅读全文
posted @ 2013-10-22 22:51 summer_zhou 阅读(159) 评论(0) 推荐(0)
摘要: 暴力法即可。不需要用kmp,太复杂了。 char *strStr(char *haystack, char *needle) { // Note: The Solution object is instantiated only once and is reused by each test case. if(!needle) return haystack; if(!haystack) return NULL; int len1 = strlen(haystack); ... 阅读全文
posted @ 2013-10-22 15:47 summer_zhou 阅读(160) 评论(0) 推荐(0)
摘要: 考虑负数做负号运算符之后的溢出问题。-INT_MIN int已经无法表示,溢出了,所以用long long来存int divide(int dividend, int divisor) { // Note: The Solution object is instantiated only once and is reused by each test case. if(divisor==0) return 0; bool bNega = false; long long divid,divis; if((dividend>0&&divisor0)) bNega = tru 阅读全文
posted @ 2013-10-22 14:45 summer_zhou 阅读(182) 评论(0) 推荐(0)
摘要: ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) { // Start typing your C/C++ solution below // DO NOT write int main() function int carry = 0; ListNode* nhead=NULL,*prev=NULL; ListNode* it1=l1,*it2=l2; while(it1||it2||carry) { int n... 阅读全文
posted @ 2013-10-22 13:40 summer_zhou 阅读(179) 评论(0) 推荐(0)
摘要: 注意边界条件即可:num1表示0或者num2表示0; string multiply(string num1, string num2) { // Note: The Solution object is instantiated only once and is reused by each test case. if(num1.empty()||num2.empty()) return ""; if(num1[0]=='0'||num2[0]=='0') //ATT here return "0";... 阅读全文
posted @ 2013-10-21 22:52 summer_zhou 阅读(121) 评论(0) 推荐(0)
摘要: string addBinary(string a, string b) { // Note: The Solution object is instantiated only once and is reused by each test case. int m = a.size(); int n = b.size(); string res(max(m,n)+1,'0'); int i = m-1,j=n-1; int carry = 0; int k = res.si... 阅读全文
posted @ 2013-10-21 22:23 summer_zhou 阅读(114) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 ··· 20 下一页