- 博客(6)
- 收藏
- 关注
原创 LeetCode 1486. 数组异或操作
给你两个整数,n 和 start 。 数组 nums 定义为:nums[i] = start + 2*i(下标从 0 开始)且 n == nums.length 。 请返回 nums 中所有元素按位异或(XOR)后得到的结果。 输入:n = 5, start = 0 输出:8 解释:数组 nums 为 [0, 2, 4, 6, 8],其中 (0 ^ 2 ^ 4 ^ 6 ^ 8) = 8 。 “^” 为按位异或 XOR 运算符。 解法一:模拟 class Solution { public: .
2021-05-07 23:21:20
177
原创 LeetCode Divide Two Integers
Given two integers dividend and divisor, divide two integers without using multiplication, division, and mod operator. Return the quotient after dividing dividend by divisor. The integer division should truncate toward zero, which means losing its fractio.
2021-05-07 19:18:17
166
原创 Leecode934.最短的桥
最短的桥 在给定的二维二进制数组 A 中,存在两座岛。(岛是由四面相连的 1 形成的一个最大组。) 现在,我们可以将 0 变为 1,以使两座岛连接起来,变成一座岛。 返回必须翻转的 0 的最小数目。(可以保证答案至少是 1。) 输入:[[0,1],[1,0]] 输出:1 输入:[[0,1,0],[0,0,0],[0,0,1]] 输出:2 这题的思路是什么呢? 给你两座岛,那么你最应该先区别开两座岛,这里岛都是用1来表示,那我我其中一座岛一定得跟另一座岛区分开来,这样对后面无论怎样都有好处,用深搜找出第一
2020-11-25 21:03:10
178
原创 Morris神级遍历C++详解
Morris二叉树神级遍历 Morris的实现原理,利用二叉树本身闲置的左右指针实现空间O(1)的遍历,怎么理解这个闲置指针呢?就是二叉树的最末节点,即没有左右孩子的节点,这个节点的左右指针都指向NULL,那么我们就可以利用一下,让当前节点的左节点的最右节点指向当前节点,有点绕,那就上图 Leetcode144 前序遍历 class Solution{ public: vector<int> preorderTraversal(TreeNode* root){ vect
2020-11-04 20:42:18
560
原创 name the year
当年份超过n,m是,循环,即取余数,注意需要判定余数为0的情况 #include #include #include using namespace std; int main(){ int n,m; char strs[25][20],strt[25][20]; scanf("%d%d",&n,&m); for(int i=1; i<=n; i++) cin>>...
2020-01-11 23:54:01
258
原创 并查集入门
并查集思想是把相互之间有关系的事物捏成一块,即使形成通路,根据通路的数量得出所要结果,分成三部分来完成,一部分初始化,一部分查找祖宗节点,另一部分判断是否未同一祖宗,若是不作处理,否则将其中一个作为另一个的祖宗。查找祖宗时用路径压缩可以节省搜索时间 #include #include #include using namespace std; const int M_ax=1005; int pr...
2020-01-11 21:58:04
704
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅