随笔分类 - C++
刷过的编程题
摘要:cpu load avg 在一段时间内,cpu正在处理的进程和等待cpu处理的进程数量的统计信息。 cpu使用率 在一段时间内,cpu被占用时间与这段时间的比值。 cpu使用率高,说明cpu已经处在高负荷的运作情况,需要调整使用频度。 cpu load avg高,说明cpu的资源竞争严重,cpu资源
阅读全文
摘要:题目地址 https://leetcode.com/problems/jump game/ 题目大意 https://leetcode cn.com/problems/jump game/ 解题思路 维护当前可以跳到的最远位置maxIndex。遍历nums,如果当前索引i不超过maxIndex, 表
阅读全文
摘要:题目地址 https://leetcode.com/problems/coin change 题目大意 https://leetcode cn.com/problems/coin change 解题思路 动态规划,自底向上,太简单,不解释。 C++代码 复杂度 1. 时间复杂度:O(m n), m是
阅读全文
摘要:题目地址 https://leetcode.com/problems/find first and last position of element in sorted array 题目大意 https://leetcode cn.com/problems/find first and last p
阅读全文
摘要:题目地址 https://leetcode.com/problems/merge intervals/ 题目大意 https://leetcode cn.com/problems/merge intervals/ 解题思路 遍历internals, 对每个internal, 与当前已经merge完成
阅读全文
摘要:题目地址 https://leetcode.com/problems/course schedule ii/ 题目大意 https://leetcode cn.com/problems/course schedule ii 解题思路 有向图的拓扑排序,采用BFS解决。对每组数字,如[1,0], 实际
阅读全文
摘要:题目地址 https://leetcode.com/problems/perfect squares/ 题目大意 给定正整数 n ,找到若干个完全平方数(比如 )使得它们的和等于 n 。你需要让组成和的完全平方数的个数最少。 解题思路 动态规划思想,dp[i]表示i的问题解, 对i开方,得到最大的平
阅读全文
摘要:题目地址 https://leetcode.com/problems/binary tree zigzag level order traversal/ 题目大意 按照层次遍历,先从左到右,再从右到左,依次如此遍历二叉树 解题思路 仍然按照从左到右层次遍历,存储上一层的遍历方向,判断若本次应该从右到
阅读全文
摘要:class Solution { public: vector modes; int maxCnt = 0; int curCnt = 0; int curNum = 0; vector findMode(TreeNode* root) { if (!root) { return modes; } ...
阅读全文
摘要:/* // Definition for a Node. class Node { public: int val; vector children; Node() {} Node(int _val, vector _children) { val = _val; children = _children; } }; *...
阅读全文
摘要:Recurisve: Iteratve:
阅读全文
摘要:题目: Given an n-ary tree, return the preorder traversal of its nodes' values. For example, given a 3-ary tree: Return its preorder traversal as: [1,3,5
阅读全文
摘要:解题思路: 设链表长度为N,每个部分的链表长度是N/k,如果N % k大于1, 从第一部分开始每个长度加一,直到N%k用完.
阅读全文
摘要:题目描述: 给一个单向链表,判断是否有环。 解题思路: 设一个慢指针和一个快指针,初始化slow为头指针,fast为头指针的next指针。 slow每次走一步,fast每次走两步,一直到fast为空,表示不存在环,或者slow指针和fast指针相遇,表示有环。 代码如下:
阅读全文
摘要:题目描述: 从一个整型链表里面移除值等于val的节点。 解题思路: 需要一个指针指向前驱节点,遍历链表,针对符合条件的节点,分两种情况处理 1)如果前驱节点不为空,前驱节点指向当前节点的下一个节点 2)如果前驱节点为空,头指针指向当前节点下一个节点 如果节点的值不等于val,前驱节点指针指向当前节点
阅读全文
摘要:Your runtime beats 100.00 % of cpp submissions.
阅读全文
摘要:char * const * (*a) (int b), 按照c++ program language的读法,从右往左读,* 读作pointer to 把(*a) (int b看作整体, (*a) (int b) is a pointer to a const pointer to char , 而
阅读全文
摘要:题目地址: https://leetcode.com/problems/min-cost-climbing-stairs/description/ 解题思路: 官方给出的做法是倒着来,其实正着来也可以,无非就是进入某个step有两种方式,退出某一个 step也有两种方式,因此若用dp[i]表示进入第
阅读全文
摘要:题目地址: https://leetcode.com/problems/house-robber/description/ 题目描述: 实际为从一组数中取出不相邻的数,使得他们的和最大。 解题思路: 动态规划,其实就是判断当前的数是否取舍,定一个数组dp,dp[i]表示第i个时能取得的 最大值,比较
阅读全文

浙公网安备 33010602011771号