上一页 1 ··· 6 7 8 9 10 11 12 下一页
摘要: 没啥困难的,唯一有问题的就是边界问题,这个可以参见整数倒置的解法。不过不同的题做法不一致,这个题更简单一点,贴代码 class Solution { public: int myAtoi(string s) { int i = 0; long result = 0; bool zheng = tru 阅读全文
posted @ 2021-03-12 17:44 zhaohhhh 阅读(44) 评论(0) 推荐(0)
摘要: 判断回文串,是之前做的找到最大回文串的简化版。但是该问题最大的难度在于ASCII码的分布,感谢这道题让我知‘P’-‘0’也等于32,贴代码 class Solution { public: bool isPalindrome(string s) { int n = s.length(); if(n 阅读全文
posted @ 2021-03-12 17:17 zhaohhhh 阅读(69) 评论(0) 推荐(0)
摘要: 题意就是判断两个字符串中的字符是否是相同且位置发生变化的,自己的思路是建立一个哈希表,遍历第一个字符串并将元素填入哈希表中,之后遍历第二个字符串,对每一个字符,如果该字符对应的哈希表中的值为0,则代表两个字符串中某一字符的数目并不相同,于是返回false,如果全部完成判断之后,就代表两个字符串对于的 阅读全文
posted @ 2021-03-12 15:35 zhaohhhh 阅读(37) 评论(0) 推荐(0)
摘要: 自己的思路并不困难,通过遍历一遍字符串,将对应的字符填入哈希表,完成一次遍历后再次遍历字符串,返回第一个哈希表中对应为1的字符的索引。 class Solution { public: int firstUniqChar(string s) { unordered_map<char,int> goo 阅读全文
posted @ 2021-03-10 15:06 zhaohhhh 阅读(43) 评论(0) 推荐(0)
摘要: 选了个先转换成字符串,然后再翻转的做法,虽然效率不差,但属实有点拉,贴代码 class Solution { public: char* inttoString(int a,char* b) { int t = a/10; if(t!=0) { b = inttoString(a/10,b) +1; 阅读全文
posted @ 2021-03-07 18:37 zhaohhhh 阅读(42) 评论(0) 推荐(0)
摘要: 就这? class Solution { public: void reverseString(vector<char>& s) { int n = s.size(); int i = 0; int j = n-1; while(i<j) { swap(s[i++],s[j--]); } } }; 阅读全文
posted @ 2021-03-07 17:13 zhaohhhh 阅读(32) 评论(0) 推荐(0)
摘要: 旋转图像,想到的方法是以每一圈为单位,进行圈上的元素的旋转,完成每一个圈的旋转之后,就完成了整体的旋转,思路不困难,难度在于旋转时变量下标的确定,刚开始走了很多弯路,后来发现一定要把具体的数值写出来,找到不变的量,使其清晰起来,就会好搞很多,贴代码 class Solution { public: 阅读全文
posted @ 2021-03-07 11:06 zhaohhhh 阅读(70) 评论(0) 推荐(0)
摘要: 咋办呢,只会暴力算法,9行9列9个9宫格,疯狂遍历完事,贴代码 class Solution { public: bool isValidSudoku(vector<vector<char>>& board) { for(int i = 0 ; i < 9 ; i++) //9行 { unorder 阅读全文
posted @ 2021-03-06 16:48 zhaohhhh 阅读(54) 评论(0) 推荐(0)
摘要: 第一反应只会写冒泡的,但是注意要从后往前冒泡,每遇到一个0就一直向后交换,直到最后,不然遍历的时候会把未遍历到的0的位置改变,导致缺失,贴代码。 class Solution { public: void moveZeroes(vector<int>& nums) { int n = nums.si 阅读全文
posted @ 2021-03-06 15:25 zhaohhhh 阅读(60) 评论(0) 推荐(0)
摘要: 题目的意思是需要考虑进位,总体上还是比较简单的,分成三种情况,第一种,最后位不为9,直接加1,第二种,不是所有位数为9,进几个位就行了,第三种,所有位数为9,也很好搞,贴代码 class Solution { public: vector<int> plusOne(vector<int>& digi 阅读全文
posted @ 2021-03-06 14:05 zhaohhhh 阅读(53) 评论(0) 推荐(0)
上一页 1 ··· 6 7 8 9 10 11 12 下一页