摘要: bool validPalindrome(char * s){ for (int i = 0, j = strlen(s)-1; i < j; ++i, --j) if (s[i] != s[j]) return (judge(s, i+1,j) || judge(s, i,j-1)); retur 阅读全文
posted @ 2020-08-26 23:29 温暖了寂寞 阅读(115) 评论(0) 推荐(0) 编辑
摘要: char pairs(char a) { if (a == '}') return '{'; if (a == ']') return '['; if (a == ')') return '('; return 0; } bool isValid(char* s) { int n = strlen( 阅读全文
posted @ 2020-08-26 20:10 温暖了寂寞 阅读(124) 评论(0) 推荐(0) 编辑
摘要: . /* 1 = 1; 4 = 1 + 3; 9 = 1 + 3 + 5; 16 = 1 + 3 + 5 + 7; */ 计算过程只需要加减法,效率极高。 bool isPerfectSquare(int num){ if (num == 0 ) return false; int i = 1; w 阅读全文
posted @ 2020-08-26 12:00 温暖了寂寞 阅读(175) 评论(0) 推荐(0) 编辑
摘要: bool isAlienSorted(char ** words, int wordsSize, char * order){ if (wordsSize == 1) return true; int i,j,k; for (i=0; i<wordsSize-1; i++) { int len = 阅读全文
posted @ 2020-08-26 11:31 温暖了寂寞 阅读(274) 评论(0) 推荐(0) 编辑
摘要: int numWaterBottles(int numBottles, int numExchange){ int total = 0; int spaceBottels = 0; while(numBottles) { total+=numBottles; spaceBottels = numBo 阅读全文
posted @ 2020-08-26 09:37 温暖了寂寞 阅读(167) 评论(0) 推荐(0) 编辑
摘要: bool wordPattern(char * pattern, char * str){ char **hash = (char **)malloc(26 * sizeof(char*)); for (int i = 0; i < 26; ++i) { hash[i] = (char*)mallo 阅读全文
posted @ 2020-08-26 00:03 温暖了寂寞 阅读(160) 评论(0) 推荐(0) 编辑