![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
llc9725
这个作者很懒,什么都没留下…
展开
-
Leetcode 48. 旋转图像
https://leetcode-cn.com/problems/rotate-image/class Solution {public: //先转置,再交换列 void rotate(vector<vector<int>>& matrix) { int n=matrix.size(); for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){原创 2022-01-06 10:24:58 · 506 阅读 · 0 评论 -
Leetcode 1116. 打印零与奇偶数
https://leetcode-cn.com/problems/print-zero-even-odd/利用四把锁同步线程class ZeroEvenOdd {private: int n; mutex a,b,c,d;public: ZeroEvenOdd(int n) { this->n = n; b.lock(); c.lock(); d.lock(); } // printNum原创 2021-11-22 11:17:37 · 109 阅读 · 0 评论 -
Leetcode.563 二叉树的坡度
https://leetcode-cn.com/problems/binary-tree-tilt/class Info{ public: int tilt=0;//当前节点坡度 int sum=0;//以当前节点为根的树的和 Info(int t,int s):tilt(t),sum(s){}; };class Solution {public: Info process(TreeNode* node){ if(!node) retu原创 2021-11-18 20:31:44 · 316 阅读 · 0 评论 -
Leetcode 24.两两交换链表中的节点
https://leetcode-cn.com/problems/swap-nodes-in-pairs/指针指的有点烦,在纸上多画画就好 ListNode* swapPairs(ListNode* head) { if(!head||!head->next) return head; ListNode* newhead=new ListNode(-1);//虚拟头节点 auto pre=newhead;//已经被反转链表的尾节点原创 2021-11-11 17:27:01 · 225 阅读 · 0 评论 -
Leetcode575 分糖果
https://leetcode-cn.com/problems/distribute-candies/先在hash表中记录下每种糖果的数量,遍历原数组,优先只有一个的该种糖果分配给妹妹(是一种贪心),如果该种糖果数量大于1,则分配给弟弟。 int distributeCandies(vector<int>& candyType) { int n(candyType.size()); int ans=0; unordered_ma原创 2021-11-01 15:10:32 · 47 阅读 · 0 评论 -
LeetCode869 重新排序得到 2 的幂
LeetCode869 重新排序得到 2 的幂https://leetcode-cn.com/problems/reordered-power-of-2/先求出一个数的全排列,然后判断全排列中是否有一个数是2的幂 void permutation(string nums,int deep,vector<int>& ans){ if(deep==nums.size()&&nums[0]!='0'){ ans.push_ba原创 2021-10-28 10:38:01 · 69 阅读 · 0 评论 -
Leecode 662(二叉树最大宽度)
#Leecode 662https://leetcode-cn.com/problems/maximum-width-of-binary-tree/思路:层次遍历,用map记录记录每个节点的编号。为防止编号溢出,每个节点编号减去上层最后一个节点的编号,也可使用 unsigned long long。 int widthOfBinaryTree(TreeNode* root) { if(!root) return 0; queue<TreeNode*> q原创 2021-10-25 22:30:00 · 89 阅读 · 0 评论