[LeetCode C++实现]124. Binary Tree Maximum Path

二叉树的题目虽然标着hard类型,但解起来有点爽,这道题目琢磨透了觉得非常的棒,可以说这种类型题目是一种套路。可以结合文章段错误segment fault分析一起使用更佳。或许屏幕前的朋友会有疑问,这篇讲函数调用栈的文章和leetcode124有啥关系?其实树里面很多递归的逻辑就是函数调用,直到调用到终止条件,然后层层向上返回的过程。

题目:

Given a non-empty binary tree, find the maximum path sum.

For this problem, a path is defined as any sequence of nodes ......

[LeetCode C++实现]78.Subsets

加班回来同事微信发来一道题目说这是整个leetcode中最棒的一道题目获益良多,本着我坚决不信的态度,尝试了两种平平无奇的解法后正打算开喷,在讨论区看到一种位运算的方法,好吧,我承认这是最棒的一道题。

Given a set of distinct integers, nums, return all possible subsets (the power set).

Note: The solution set must not contain duplicate subsets.

Example:

Input: nums = [1,2,3]

Output:

[

[3],

[1],

[......

[LeetCode C++实现]347. Top K Frequent Elements

Given a non-empty array of integers, return the k most frequent elements.

Example 1:

Input: nums = [1,1,1,2,2,3], k = 2

Output:

Example 2:

Input: nums = [1], k = 1

Output:

Note:

You may assume k is always valid, 1 ≤ k ≤ number of unique elements.

Your algorithm's time complexity......