刷题的日常
leetcode反复刷题,做了就忘,忘了做,做了忘。。。煎熬啊!!!
液压姬
这个作者很懒,什么都没留下…
展开
-
【队栈】leetcode_225_用队列实现栈
【队栈】leetcode_225_用队列实现栈class MyStack {public: /** Initialize your data structure here. */ MyStack() { } /** Push element x onto stack. */ void push(int x) { qun1.push(x); } /** Removes the element on top of原创 2021-05-12 21:18:20 · 114 阅读 · 0 评论 -
【树】leetcode_106_从后序与中序遍历序列构造二叉树
【树】leetcode_106_从后序与中序遍历序列构造二叉树/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left原创 2021-05-09 16:56:45 · 100 阅读 · 0 评论 -
【树】leetcode_105_从前序与中序遍历序列构造二叉树
【树】leetcode_105_从前序与中序遍历序列构造二叉树/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left原创 2021-05-09 16:55:47 · 100 阅读 · 0 评论 -
【树】【回溯】leetcode_113_路径总和II
【树】【回溯】leetcode_113_路径总和II/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(null原创 2021-05-08 11:38:45 · 88 阅读 · 0 评论 -
【树】【回溯】leetcode_112_路径总和
【树】【回溯】leetcode_112_路径总和/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullpt原创 2021-05-08 10:26:15 · 78 阅读 · 0 评论 -
【树】leetcode_404_左叶子之和
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} *原创 2021-05-07 10:07:53 · 83 阅读 · 0 评论 -
【树】leetcode_100_相同的树
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} *原创 2021-05-07 10:07:13 · 56 阅读 · 0 评论 -
【树】leetcode_513_找树左下角的值
【树】leetcode_513_找树左下角的值/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr原创 2021-05-07 10:06:58 · 67 阅读 · 0 评论 -
【树】leetcode_572_另一个树的子树
【树】leetcode_572_另一个树的子树/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr原创 2021-05-05 16:17:39 · 60 阅读 · 0 评论 -
【树】【回溯】 leetcode_257 _ 二叉树的所有路径
【树】【回溯】 leetcode_257 _ 二叉树的所有路径/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left原创 2021-05-04 21:37:01 · 68 阅读 · 0 评论 -
【树】 leetcode_111 _ 二叉树的最小深度
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} *原创 2021-05-04 17:15:18 · 60 阅读 · 0 评论 -
【树】leetcode_559_ N 叉树的最大深度
【树】leetcode_559_ N 叉树的最大深度/*// Definition for a Node.class Node {public: int val; vector<Node*> children; Node() {} Node(int _val) { val = _val; } Node(int _val, vector<Node*> _children) { val = _v原创 2021-05-04 17:14:29 · 69 阅读 · 0 评论 -
【树】 leetcode_222 _ 完全二叉树的节点个数
后序递归/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {原创 2021-05-04 16:08:31 · 56 阅读 · 0 评论 -
【树】 leetcode_110 _ 平衡二叉树
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} *原创 2021-05-04 15:39:09 · 115 阅读 · 0 评论 -
【树】leetcode_589_N 叉树的前序遍历
【树】leetcode_589_N 叉树的前序遍历/*// Definition for a Node.class Node {public: int val; vector<Node*> children; Node() {} Node(int _val) { val = _val; } Node(int _val, vector<Node*> _children) { val = _va原创 2021-04-26 18:16:56 · 72 阅读 · 0 评论 -
【树】leetcode_590_N 叉树的后序遍历
【树】leetcode_590_N 叉树的后序遍历/*// Definition for a Node.class Node {public: int val; vector<Node*> children; Node() {} Node(int _val) { val = _val; } Node(int _val, vector<Node*> _children) { val = _va原创 2021-04-26 18:04:23 · 58 阅读 · 0 评论 -
【栈】leetcode_20_有效的括号
【栈】leetcode_20_有效的括号class Solution {public: bool isValid(string s) { stack<char> res; for (char i : s){ if (i == '('){ res.push(')'); }else if (i == '{'){ res.push('}');原创 2021-04-14 21:57:13 · 75 阅读 · 0 评论 -
【栈】leetcode_1190_反转每对括号间的子串【华为2022】
1.括号与括号之间为一段2.遇到左括号,当前这一段存入stack3.遇到右括号,当前这一段翻转,可以与前一段拼接了。4.一直进行。即可得到结果。class Solution {public: string reverseParentheses(string s) { stack<string> s_st; string input = s; string res; for(char &c : input)原创 2021-04-14 21:33:54 · 121 阅读 · 0 评论 -
【树】[递归的典型] leetcode_104. 二叉树的最大深度
【树】[递归的典型] leetcode_104. 二叉树的最大深度递归/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x),原创 2021-04-14 16:01:34 · 59 阅读 · 0 评论 -
【树】[递归的典型] leetcode_226_翻转二叉树
【树】[递归的典型] leetcode_226_翻转二叉树递归-前序-后序都行,中序的话(左翻转,中翻转的时候会把左再翻一遍,所以不行)/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {}原创 2021-04-14 15:30:26 · 76 阅读 · 0 评论 -
【树】[递归的典型] leetcode_101_对称二叉树
【树】leetcode_101_对称二叉树/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr),原创 2021-04-13 21:58:15 · 89 阅读 · 0 评论 -
【树】leetcode_429_N 叉树的层序遍历
【树】leetcode_429_N 叉树的层序遍历/*// Definition for a Node.class Node {public: int val; vector<Node*> children; Node() {} Node(int _val) { val = _val; } Node(int _val, vector<Node*> _children) { val = _va原创 2021-04-13 20:36:54 · 81 阅读 · 0 评论 -
【树】leetcode_637_二叉树的层平均值
【树】leetcode_637_二叉树的层平均值class Solution {public: vector<double> averageOfLevels(TreeNode* root) { TreeNode *cur = root; vector<double> result; if (root == nullptr) return {}; queue<TreeNode*> q_node;原创 2021-04-13 16:53:55 · 75 阅读 · 0 评论 -
【树】leetcode_199_二叉树的右视图
【树】leetcode_199_二叉树的右视图/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr原创 2021-04-13 16:33:10 · 59 阅读 · 0 评论 -
【树】leetcode_107_ 二叉树的层序遍历 II
【树】leetcode_107_ 二叉树的层序遍历 II/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nu原创 2021-04-13 15:59:41 · 60 阅读 · 0 评论 -
【树】leetcode_102_ 二叉树的层序遍历
【树】leetcode_145_ 二叉树的后序遍历/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullp原创 2021-04-09 21:53:06 · 94 阅读 · 0 评论 -
【树】leetcode_94_二叉树的中序遍历
【树】leetcode_94_二叉树的中序遍历c++迭代,/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(原创 2021-04-09 10:05:00 · 78 阅读 · 0 评论 -
【树】leetcode_145_ 二叉树的后序遍历
【树】leetcode_145_ 二叉树的后序遍历c++递归class Solution {public: vector<int> postorderTraversal(TreeNode* root) { vector<int> re; get_re(root, re); return re; } void get_re(TreeNode *root, vector<int> &re)原创 2021-04-08 20:43:02 · 70 阅读 · 0 评论 -
【树】leetcode_114_二叉树的前序遍历
【树】leetcode_114_二叉树展开为链表c++递归,回顾一下,/** * Definition for a binary tree node. * struct TreeNode * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x),原创 2021-04-08 18:59:32 · 89 阅读 · 0 评论 -
【树】leetcode_144_二叉树展开为链表
【树】leetcode_144_二叉树展开为链表c++(自己写的好烂啊。。。把val存到列表中,然后从新建一个二叉树,之前的二叉树也没删掉。。)/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullpt原创 2021-04-08 18:45:00 · 80 阅读 · 0 评论 -
【队栈】leetcode_232_用栈实现队列
【队栈】leetcode_232_用栈实现队列c++class MyQueue {public: stack<int> s_in; stack<int> s_out; /** Initialize your data structure here. */ MyQueue() { } /** Push element x to the back of queue. */ void push(int x) {原创 2021-04-06 22:48:28 · 73 阅读 · 0 评论 -
【字符串】剑指 Offer 58 - II_左旋转字符串
【字符串】剑指 Offer 58 - II_左旋转字符串c++(直截了当法)class Solution {public: string reverseLeftWords(string s, int n) { string re(s.begin()+n,s.end()); s.erase(s.begin()+n,s.end()); s.insert(0,re); return s; }};多次翻转法class So原创 2021-04-02 20:57:29 · 51 阅读 · 0 评论 -
【字符串】leetcode_151_翻转字符串里的单词
【字符串】leetcode_151_翻转字符串里的单词#include <iostream>#include <string>#include <algorithm>using namespace std;class Solution {public: string reverseWords(string s) { //去除多余空格 for (int i = s.size()-1; i>=0; i--){原创 2021-04-02 09:33:25 · 71 阅读 · 0 评论 -
【字符串】剑指 Offer 05_替换空格
【字符串】剑指 Offer 05_替换空格c++(扩充string,然后用双指针法)class Solution {public: string replaceSpace(string s) { int s_OldSize = s.size(); int count = 0; for (int i = 0; i<s_OldSize; i++){ if (s[i] == ' ') count++;原创 2021-03-30 20:36:12 · 55 阅读 · 0 评论 -
【字符串】leetcode_541_反转字符串 II
【字符串】leetcode_541_反转字符串 IIc++class Solution {public: string reverseStr(string s, int k) { int length = s.size(); for (int i = 0; i<length; i+=2*k){ if ((i+k) <= length){ reverse(s.begin()+i,原创 2021-03-30 17:22:17 · 73 阅读 · 0 评论 -
【字符串】leetcode_344_反转字符串
【字符串】leetcode_344_反转字符串c++(需要一道傻瓜题找点自信。。。)class Solution {public: void reverseString(vector<char>& s) { int left = 0; int right = s.size()-1; for (;left<right;left++){ swap(s[left],s[right]);原创 2021-03-29 21:50:52 · 64 阅读 · 0 评论 -
【哈希表】leetcode_15_三数之和
【哈希表】leetcode_15_三数之和python (自己写的。。。超时了。。。我好菜啊)class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: re = [] for i in range(len(nums) - 1): for j in range(i+1, len(nums)): de = nums[:]原创 2021-03-27 17:29:15 · 116 阅读 · 0 评论 -
【哈希表】leetcode_454_四数相加 II
【哈希表】leetcode_454_四数相加 IIc++class Solution {public: int fourSumCount(vector<int>& A, vector<int>& B, vector<int>& C, vector<int>& D) { map<int,int> myMap; int count = 0; for(原创 2021-03-26 14:44:32 · 92 阅读 · 0 评论 -
【哈希表】leetcode_383_赎金信
【哈希表】leetcode_383_赎金信python(字符串str的删除指定元素可以用replace(new,old,count)class Solution: def canConstruct(self, ransomNote: str, magazine: str) -> bool: for i in ransomNote: if i in magazine: magazine = magazine.replac原创 2021-03-26 11:26:54 · 89 阅读 · 0 评论 -
【链表】leetcode_83_删除排序链表中的重复元素
【链表】leetcode_83_删除排序链表中的重复元素c++/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, Lis原创 2021-03-25 16:16:09 · 65 阅读 · 0 评论