随笔分类 - LeetCode
摘要:题目链接:http://oj.leetcode.com/problems/maximum-depth-of-binary-tree/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.解法:递归;父节点的深度等于左子树/右子树中深度大者+1 1 /** 2 * Definition for binary tree 3 * stru..
阅读全文
摘要:题目链接:http://oj.leetcode.com/problems/single-number-ii/Given an array of integers, every element appearsthreetimes except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?解法:由于数组中所有元素都是整型,整型长度为32位,可以用一个数组count
阅读全文
摘要:链接:http://oj.leetcode.com/problems/single-number/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?解法:可以根据异或运算的配对性定理可以解此题.配对性定理可以详见:http://wenku.bai
阅读全文

浙公网安备 33010602011771号