摘要:
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.递归版本:class Solution {public: int maxDepth(TreeNode *root) { if(!root) return 0; // !root else return max(maxDepth(root->left... 阅读全文
摘要:
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from B. The number of elements initialized in A and B are m and n respectively.class Solution {public: void ... 阅读全文
摘要:
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?no extra memory solution:class Solution {public: int singleNumber(int A[], int n) { ... 阅读全文
摘要:
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?class Solution {public: int singleNumber(int A[], int n) { int sinNum; for(int i ... 阅读全文