代码改变世界

leetcode - Word Search

2013-12-15 21:00 by 张汉生, 136 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 int m, n; 4 bool search(vector > &board, string & word, int x, int y, vector >&flag, int off){ 5 if (off == word.size()) return true; 6 int dx[4] = { -1, 0, 1, 0 }; 7 int dy[4] = { 0, -1, 0, 1 }; 8 for (int i = 0; i = 0 && xx = ... 阅读全文

leetcode - Minimum Window Substring

2013-12-14 21:45 by 张汉生, 184 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 //reference: http://www.cnblogs.com/remlostime/archive/2012/11/16/2774077.html 4 string minWindow(string S, string T) { 5 int flag[128]; 6 memset(flag, 0, sizeof(flag)); 7 int lenT = T.length(); 8 if (lenT end - start + 1){33 ... 阅读全文

leetcode - Palindrome Partitioning II

2013-12-14 09:38 by 张汉生, 165 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 bool isPal(const char * p, const char * q){ 4 while (p ePos(n+1, -1);19 while ((*p) != '\0'){20 const char * q = head;21 int curMax = 1000000000;22 while (q<=p){23 if (curMax<=1+ePos[q-head] || !i... 阅读全文

leetcode - Palindrome Partitioning

2013-12-14 09:23 by 张汉生, 213 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 bool isPal(const char * p, const char * q){ 4 while (p > partition(string s) {12 int n = s.length();13 if (n>(1,vector(1,""));15 const char * head = s.c_str();16 const char * end = head + n-1;17 const char * p = head... 阅读全文

leetcode - Wildcard Matching

2013-12-11 11:24 by 张汉生, 143 阅读, 0 推荐, 收藏, 编辑
摘要:// token form http://blog.csdn.net/sunbaigui/article/details/8981369// still need more checkclass Solution { //if strlen is used, then it will be TLE //iteration based solution public: bool isMatch(const char *s, const char *p) { // Start typing your C/C++ solution below //... 阅读全文

leetcode - Multiply Strings

2013-12-10 18:19 by 张汉生, 127 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 string multiply(string num1, string num2) { 4 // IMPORTANT: Please reset any member data you declared, as 5 // the same Solution instance will be reused for each test case. 6 int len1 = num1.length(); 7 int len2 = num2.length(); 8 ... 阅读全文

leetcode - Surrounded Regions

2013-12-10 17:57 by 张汉生, 181 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 struct point{ 4 int x; 5 int y; 6 point(int _x, int _y):x(_x),y(_y){} 7 }; 8 void solve(vector > &board){ 9 if (board.size() flag(n, false);14 vector >visitFlag(m, flag);15 vector >checkFlag(m, flag);16 ... 阅读全文

leetcode - Valid Palindrome

2013-12-10 15:44 by 张汉生, 151 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 int getNum(char c){ 4 if (c>='a' && c='A' && c='0' && c=0){18 char x = s.at(i);19 int a = getNum(x);20 if (a==-1){21 i++;22 continue;23 }24 char y = s.at(j);25 int b = getNum(y);26 if (b==... 阅读全文

leetcode - Sudoku Solver

2013-12-10 14:26 by 张汉生, 388 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 bool solveSudoku(vector > & board, vector > > & flag, int x, int y){ 4 bool wEnd = (x == 8 && y == 8) ? true: false; 5 int nextX = y > &board) {30 vector vb(9,false);31 vector > vvb (9, vb);32 vector > > flag(3, vvb);33 for (int 阅读全文

leetcode - Text Justification

2013-12-09 16:04 by 张汉生, 207 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 vector fullJustify(vector &words, int L) { 4 // IMPORTANT: Please reset any member data you declared, as 5 // the same Solution instance will be reused for each test case. 6 int n = words.size(); 7 int i =0; 8 vector > rlts; 9 vecto... 阅读全文
上一页 1 2 3 4 5 6 ··· 16 下一页