摘要: I动态规划,一次性构造,查询。采用回溯法会超时class Solution {public:int grid[100][100]; int uniquePaths(int m, int n) { if(grid[m-1][n-1]==0) construct(); return grid[m-1][n-1]; } void construct() { grid[0][0]=1; for(int i=1;i<100;i++) { grid[i][0]=1; } ... 阅读全文
posted @ 2013-05-29 15:14 代码改变未来 阅读(322) 评论(0) 推荐(0) 编辑
摘要: 回文数字,比较简单class Solution {public: bool isPalindrome(int x) { if(x<0)return false; int y=x; int z=0; while(y>0) { int k=y%10; z=z*10+k; y=y/10; } if(z==x)return true; else return false; }}; 阅读全文
posted @ 2013-05-29 14:34 代码改变未来 阅读(144) 评论(0) 推荐(0) 编辑
摘要: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) { ListNode *head; ListNode *p=l1,*q=l2; if(p=... 阅读全文
posted @ 2013-05-29 14:03 代码改变未来 阅读(490) 评论(0) 推荐(0) 编辑