摘要:
/* 题目: 求数组A中只出现一次的数字,该数组中有2个数字a、b仅出现一次,其余均出现两次 */ /* 思路: 两个相同的数字异或为0. 遍历数组,得到数组中各数字异或后的结果x,结果x=a^b。 x中肯定存在一位不为0,找到左起第一位为1的位。 根据该位,将数组分为两拨,再进行异或,得到的结果即 阅读全文
posted @ 2019-12-25 18:02
笨宝宝
阅读(150)
评论(0)
推荐(0)
摘要:
/* 题目: 判断二叉树是否为平衡二叉树。 */ /* 思路: 判断二叉树的左子树和右子树高度相差是否为1. */ #include<iostream> #include<cstring> #include<vector> #include<algorithm> #include<map> usin 阅读全文
posted @ 2019-12-25 17:07
笨宝宝
阅读(169)
评论(0)
推荐(0)
摘要:
/* 题目: 二叉树的深度 */ /* 思路: 根节点高度(0或1)+左子树的深度+右子树的深度 */ #include<iostream> #include<cstring> #include<vector> #include<algorithm> #include<map> using name 阅读全文
posted @ 2019-12-25 16:10
笨宝宝
阅读(105)
评论(0)
推荐(0)
浙公网安备 33010602011771号