摘要:
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.分析:这一题是说求出二叉树的最大深度,很显然我们会想到递归,很容易实现。/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *... 阅读全文
摘要:
Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?分析:给出一组数组,每个元素都出现两次,只有一个元素只出现一次。要求不需要额外的存储空间,时间复杂度是O(n)。我们想到一个性质:任何一个数字与自己异或的结果都为0,故可以想到数组中一个元素出现两 阅读全文