题目: Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it. Follow up: Could you do it withou…
标题 Maximum Depth of Binary Tree 描述 The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. c++实现方法代码 1.递归实现,时间复杂度为O(n) 空间复杂度为O(logn) /** * Definition for binary tree * struct TreeNode { * int…
问题描述 Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority element always exist in the array. 解决思路: 推荐算法: Moore votin…