刷题
JustNow_Man
计算机,努力学习中·ye
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
【刷题】OJ输入输出练习
输入输出练习 对于有不定行输入的情况,使用while输入; 对于指定行数的情况,使用for输入; 对于需要分行的情况,使用getchar() != '\n'进行分行; 对于分割字符串的情况,使用 include <sstream> string line, item; stringstream ss(line); while(getline(ss, item, ',') { vecstr.push_back(item); } ...原创 2021-11-20 10:02:18 · 364 阅读 · 0 评论 -
【二叉树】完全二叉树的节点数
使用O(logNlogN)算法时间复杂度计算完全二叉树的节点数量; class Solution { public: // 算法时间复杂度为 = 算法递归深度 * 每次递归所花的时间; // = 树的高度(O(logN)) * while循环(O(logN)); // 分解成:满二叉树和完全二叉树的节点数量计算 int countNodes(TreeNode* root) { if (root == nullptr) {原创 2021-08-08 11:05:30 · 184 阅读 · 0 评论 -
【Daily Practice】316. 去除重复字母
leetcode 316题 理解思路,暂不能保证AC; class Solution { public: string removeDuplicateLetters(string s) { stack<char> st; int *countArr = new int[256]{0}; for (int i = 0; i < s.size(); i++) { countArr[s[i]]++;原创 2021-08-07 10:01:59 · 153 阅读 · 0 评论 -
【二叉树】最大二叉树
对于构造二叉树的问题,根节点要做的是想办法把自己构造出来(找出maxValue),然后对maxValue左边数组和右边数组进行递归调用,作为root的左右子树。 先序遍历来解题 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullpt.原创 2021-08-05 08:27:38 · 310 阅读 · 0 评论 -
【二叉树】二叉树展开为链表
写树的相关算法,简单说就是先搞清楚当前root节点该做什么以及什么时候做,然后根据函数定义递归调用子节点。 该做什么:想清楚写代码能实现题目的效果; 什么时候做:想清楚这段代码是该写在前序、中序还是后序遍历的代码位置上。 解题流程 将root的左子树和右子树拉平; 将root的右子树接到左子树下方,然后将整个左子树作为右子树; 实现 /** * Definition for a binary tree node. * struct TreeNode { * int val; * .原创 2021-08-04 08:31:26 · 154 阅读 · 0 评论 -
【二叉树】226.反转二叉树
/** * 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-08-03 08:21:10 · 122 阅读 · 0 评论 -
【Practice Daily】LRF算法题解
460.LFU缓存 struct Node { int cnt, time, key, value; Node(int _cnt, int _time, int _key, int _value):cnt(_cnt), time(_time), key(_key), value(_value){} bool operator < (const Node& rhs) const { return cnt == rhs.cnt ? time &l原创 2021-08-01 10:33:47 · 300 阅读 · 0 评论 -
【Leetcode】总结
739 每日温度 ERROR: st为空时,仍取其中的值: while (temperatures[i] > temperatures[st.top()] && !st.empty()) { res[st.top()] = i - st.top(); st.pop(); /* # 修改正确方式 if (st.empty()) { break; }原创 2021-06-14 22:55:06 · 126 阅读 · 0 评论
分享