随笔分类 - leetcode系列
摘要:```c /* Author: Zoro Date: 2019/11/10 Function: Valid Anagram Title: leetcode 242 anagram.c think: 桶排序思想 */ #include #include #include bool isAnagram(char *s, char *t) { int statS[26] = {0}; int statT
阅读全文
摘要:```c /* Author: Zoro Date: 2019/11/10 Function: Majority Element Title: leetcode 169 think: 出现的次数最多,且大于数组的二分之一 两种方法:统计方法,数据结构法 1: 空 入栈 2: 栈顶 = 元素 入栈 3: 其它情况 出栈 majority.c 时间复杂度: O(n) 空间复杂度: O(n) */ #i
阅读全文
摘要:```c //有符号整数溢出:964632435 10不能用类型“int”表示 //1534236469 int reverse(int x){ long int y = 0; while (x != 0) { y = (x % 10)+ y 10; x /= 10; if (y INT_MAX |
阅读全文
摘要:算法 1 初始化栈 S。 2 一次处理表达式的每个括号。 3 如果遇到开括号,我们只需将其推到栈上即可。这意味着我们将稍后处理它,让我们简单地转到前面的 子表达式。 4 如果我们遇到一个闭括号,那么我们检查栈顶的元素。如果栈顶的元素是一个 相同类型的 左括号,那么我们将它从栈中弹出并继续处理。否则,
阅读全文
摘要:```c int romanToInt(char s){ // int a[13] = {1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000 }; int i = 0, k, sum = 0; while (s[i]) { switch (s[i
阅读全文