上一页 1 2 3 4 5 6 7 ··· 16 下一页
摘要: 1.solve数独dfsclass Solution{public: bool isValid(vector<vector<char> > &board, int x, int y) { int i, j; for (i = 0; i < 9; i++) if (i != x && board[i][y] == board[x][y]) return false; for (j = 0; j < 9; j++) if (j != y && board[x][j] == board[x][y]) return false 阅读全文
posted @ 2013-06-14 20:37 代码改变未来 阅读(300) 评论(0) 推荐(0) 编辑
摘要: 1.验证数独class Solution {public:int hash[9]; bool isValidSudoku(vector<vector<char> > &board) { for(int i=0;i<9;i++) { if(isvalidRow(i,board)==false)return false; } for(int i=0;i<9;i++) { if(isvalidCol(i,board)==false)return false; } ... 阅读全文
posted @ 2013-06-14 18:33 代码改变未来 阅读(282) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: bool isMatch(const char *s, const char *p) { assert(s && p); if(*p=='\0') return *s == '\0'; if (*(p+1)!='*') { assert(*p != '*'); return ((*p == *s) || (*p == '.' && *s != '\0')) && isMatch(s+1, p+1); } 阅读全文
posted @ 2013-06-13 19:22 代码改变未来 阅读(481) 评论(0) 推荐(0) 编辑
摘要: 1.Count and Sayclass Solution {public: string countAndSay(int n) { string s1,s2=""; s1="1"; if(n==1)return s1; for(int i=1;i<n;i++) { int j=0;int k=0; while(j<s1.size()) { char c=s1[j]; while(s1[... 阅读全文
posted @ 2013-06-13 15:37 代码改变未来 阅读(124) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public int[][] generateMatrix(int n) { // Start typing your Java solution below // DO NOT write main() function int [][] matrix =new int[n][n]; int start=0, end=n-1; int num=1; while(start<end) { for(int j=start;j<end;j++) { ma... 阅读全文
posted @ 2013-06-13 00:23 代码改变未来 阅读(1562) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: int reverse(int x) { int y=abs(x); int z=0; while(y>0) { z=z*10+y%10; y=y/10; } if(x>0)return z; if(x<0)return -z; }}; 阅读全文
posted @ 2013-06-13 00:09 代码改变未来 阅读(121) 评论(0) 推荐(0) 编辑
摘要: DFS。AC的代码class Solution {public:bool flag;bool used[250][250]; bool exist(vector<vector<char> > &board, string word) { if(word=="")return true; int m=board.size(); if(m==0)return false; int n=board[0].size(); flag=false; for(int i=0;i<m;i++) { ... 阅读全文
posted @ 2013-06-09 17:07 代码改变未来 阅读(842) 评论(0) 推荐(0) 编辑
摘要: 1.Search for a Range参考剑指offer 面试题38class Solution {public: vector searchRange(int A[], int n, int target) { vectorindex; int low=0,high=n-1; int m; while(low=0&&A[i]==target;i--); index.push_back(i+1); for(j=m;jtarget)high=m-1; ... 阅读全文
posted @ 2013-06-09 15:02 代码改变未来 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 不多说了。class Solution {public: void setZeroes(vector<vector<int> > &matrix) { int m=matrix.size(); if(m==0)return; int n=matrix[0].size(); vector<int>a; vector<int>b; for(int i=0;i<m;i++) { for(int j=0;j<n;j++) { ... 阅读全文
posted @ 2013-06-09 14:41 代码改变未来 阅读(185) 评论(0) 推荐(0) 编辑
摘要: Surrounded RegionsDFSclass Solution {public: void solve(vector<vector<char>> &board) { int n=board.size(); if(n==0)return; for(int i = 1; i < n- 1; i++) { dfs(board, i, 0); dfs(board, i, n-1); } for(int j = 0; j ... 阅读全文
posted @ 2013-06-09 00:17 代码改变未来 阅读(1337) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 ··· 16 下一页