![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
简单
zhaohoutao
这个作者很懒,什么都没留下…
展开
-
LeetCode-66 加一
加一class Solution {public: vector<int> plusOne(vector<int>& digits) { int len=digits.size(); vector<int> result;//倒着来 vector<int> result_1;//正...原创 2019-07-08 18:07:06 · 62 阅读 · 0 评论 -
LeetCode-263 丑数
丑数class Solution {public: bool isUgly(int num) { //设计思路 int n=num; if(n==0) return false; while(n%2==0) { n=n/2; } whil...原创 2019-07-17 21:12:19 · 78 阅读 · 0 评论 -
LeetCode 724 寻找数组的中心索引
寻找数组的中心索引本来想用双指针的但是出现了一些问题解决不了,所以使用了一般的方法在这里插入代码片class Solution {public:int pivotIndex(vector& nums) {int len=nums.size();int sum=0;int sum_left=0;for(int j=0;j<len;++j)sum=sum+nums...原创 2019-07-20 00:18:02 · 105 阅读 · 0 评论 -
LeetCode 235 二叉搜索树的最近公共祖先
二叉搜索树的最近公共祖先/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {}...原创 2019-07-29 15:52:50 · 53 阅读 · 0 评论 -
LeetCode-205 同构字符串 LeetCode-290 单词规律
同构字符串class Solution {public: bool isIsomorphic(string s, string t) { //使用map映射机制么? //对于map的特性是key不可以重复的,但是value可以重复,所以需要再value上加功夫 map<char,char> yingshe; ...原创 2019-07-17 00:04:15 · 138 阅读 · 0 评论 -
LeetCode 203 移除链表元素
移除链表元素/**Definition for singly-linked list.struct ListNode {int val;ListNode *next;ListNode(int x) : val(x), next(NULL) {}};/class Solution {public:ListNode removeElements(ListNo...原创 2019-07-16 23:01:15 · 94 阅读 · 0 评论 -
LeetCode-258 各位相加
各位相加简单的使用循环class Solution {public:int addDigits(int num) {//各位相加int n=num;while(n/10!=0){int sum=0;while(n!=0){int temp;temp=n%10;n=n/10;sum=sum+temp;}n=sum;}return n;}};if(num...原创 2019-07-16 21:04:26 · 63 阅读 · 0 评论 -
LeetCode 234 回文链表
回文链表自己的代码超出时间/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public:...原创 2019-07-16 20:43:56 · 59 阅读 · 0 评论 -
约瑟夫环
class Solution {public: int LastRemaining_Solution(int n, int m) { int count = n; int i = -1; int step = 0; vector<int> flag(n, 0); while (count...原创 2019-07-19 00:23:59 · 469 阅读 · 0 评论 -
LeetCode-237 删除链表中的节点
删除链表中的节点/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: vo...原创 2019-07-18 23:34:19 · 56 阅读 · 0 评论 -
LeetCode 257 二叉树的所有路径
二叉树的所有路径/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }...原创 2019-07-16 18:03:46 · 69 阅读 · 0 评论 -
LeetCode-151 翻转字符串里的单词
翻转字符串里的单词class Solution {public: string reverseWords(string s) { int len = s.size(); vector<string> v_string; if (len == 0) return ""; int index = 0; for (int i = 0; i < len ...原创 2019-07-15 17:31:22 · 91 阅读 · 0 评论 -
LeetCode-169 求众数
求众数加入了一个判断得到的元素到底是不是众数,也就是前面得到的数不一定是众数。第一种方法:class Solution {public: bool panduan(vector<int> &nums, int number) { int count = 0; for (int i = 0; i<nums.size(...原创 2019-07-09 21:28:15 · 102 阅读 · 0 评论 -
LeetCode-38 报数
报数class Solution {public: string countAndSay(int n) { //使用的是什么算法呢 if (n == 1) return "1"; if (n == 2) return "11"; vector<string> a(n + 1); a[0]="0"; a[1] = "1"; a[...原创 2019-07-08 23:43:12 · 60 阅读 · 0 评论 -
LeetCode-22 有效的括号
有效的括号class Solution {public: bool isValid(string s) { //使用栈的方式进行相应的计算操作的 stack<char> sT;//对于有栈的程序一定要判断栈是否为空,可能是结束条件呢 if(s.size()==0) return true; ...原创 2019-07-08 21:08:04 · 67 阅读 · 0 评论 -
LeetCode-67 二进制求和
二进制求和原创 2019-07-08 19:15:54 · 100 阅读 · 0 评论 -
求树的最大深度和最小深度的非递归实现
求树的最大深度和最小深度的非递归实现int long_depth(TreeNode* root){ //对于这种东西使用的是队列的方式 deque<TreeNode*> deque_tree; deque_tree.push_back(root); int depth = 0; int thislevel=1; int nextlevel=0; while (!deq...原创 2019-07-21 19:44:10 · 444 阅读 · 0 评论