// Solution 1: An interesting problem. As the elements are all integers, if not encountering 0, the absolute value of the product will continue to increase. Thus the product is either min or max. By keeping watch over both ends, we have the maximum product of subarrays. This holds only...
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
In this problem, we need to tackle with the "leaf node case" very carefully. What's a leaf node? A leaf node must has no left child or right child. We should mix this case with situation that a node has only one child. Some errors I have commited to solve the problem. 1. Direc...
输入:nums = [-2,1,-3,4,-1,2,1,-5,4] 输出:6 解释:连续子数组 [4,-1,2,1] 的和最大,为 6 。 示例2: 输入:nums = [1] 输出:1 示例3: 输入:nums = [5,4,-1,7,8] 输出:23 提示: 1 <= nums.length <= 105 -104 <= nums[i] <= 104 进阶:如果你已经实现复杂度为 ...
Leetcode : 104. Maximum Depth of Binary Tree (Easy) 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. Note: A leaf is a node with no children. Example: Given binary tree [...
Dutch National Flag Problem (medium) 3. Pattern: Fast & Slow pointers, 快慢指针类型 这种模式,有一个非常出门的名字,叫龟兔赛跑。咱们肯定都知道龟兔赛跑啦。但还是再解释一下快慢指针:这种算法的两个指针的在数组上(或是链表上,序列上)的移动速度不一样。还别说,这种方法在解决有环的链表和数组时特别有...
摘要:Problem:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its index, otherwise return -1.You may assume no duplicate exists in ...
请你设计并实现一个满足LRU (最近最少使用) 缓存约束的数据结构。 实现LRUCache类: LRUCache(int capacity)以正整数作为容量capacity初始化 LRU 缓存 int get(int key)如果关键字key存在于缓存中,则返回关键字的值,否则返回-1。 void put(int key, int value)如果关键字key已经存在,则变更其数据值value;如果...
Can you solve this real interview question? Pow(x, n) - Implement pow(x, n) [http://www.cplusplus.com/reference/valarray/pow/], which calculates x raised to the power n (i.e., xn). Example 1: Input: x = 2.00000, n = 10 Output: 1024.00000 Example
The following example may help you understand the problem better: Given the 8 x 8 grid below, we want to construct the corresponding quad tree: It can be divided according to the definition above: The corresponding quad tree should be as following, where each node is represented as a...