// 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.
53. 最大子数组和 - 给你一个整数数组 nums ,请你找出一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。 子数组 是数组中的一个连续部分。 示例 1: 输入:nums = [-2,1,-3,4,-1,2,1,-5,4] 输出:6 解释:连续子数组 [4,-1,2,1] 的和最大,为
Subarrays with Product Less than a Target (medium) Dutch National Flag Problem (medium) 3. Pattern: Fast & Slow pointers, 快慢指针类型 这种模式,有一个非常出门的名字,叫龟兔赛跑。咱们肯定都知道龟兔赛跑啦。但还是再解释一下快慢指针:这种算法的两个指针的在数组上(或是链表上,序列上)的移动速度不...
请你设计并实现一个满足LRU (最近最少使用) 缓存约束的数据结构。 实现LRUCache类: LRUCache(int capacity)以正整数作为容量capacity初始化 LRU 缓存 int get(int key)如果关键字key存在于缓存中,则返回关键字的值,否则返回-1。 void put(int key, int value)如果关键字key已经存在,则变更其数据值value;如果...
Notes: It is intended for this problem to be specified vaguely (ie, no given input specs). You are responsible to gather all the input requirements up front. spoilers alert… click to show requirements for atoi. Requirements for atoi: The function first discards as many whitespace characters ...
Problem 1: Leetcode 40 给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。 candidates 中的每个数字在每个组合中只能使用一次。 比方说candidates = [10,1,2,7,6,1,5], target = 8,那么输出就是 ...
testHead=testHead.next; } }if(!valid){break; }if(pre ==null){ pre=testHead; ret=pre; }else{ pre.next=testHead; } ListNode oldPre=current; ListNode next=current.next; current.next=testHead.next; pre=current; current=next;for(inti = 1; i < k; ++i){ ...
The Skyline Problem 219. Contains Duplicate II 220. Contains Duplicate III 222. Count Complete Tree Nodes 223. Rectangle Area 224. Basic Calculator 225. Implement Stack using Queues 226. Invert Binary Tree 229. Majority Element II 230. Kth Smallest Element in a BST 231. Power of Two 232. ...
Leet code problem 217 Jan 11, 2023 21_Merge_linked_lists Solve leetcode question 21 Mar 15, 2023 22_Generate_Parenthesis.java Improve leetcode question 22 Jan 13, 2023 238_Product_of_Array_Except_Self Solved leetcode question 238 Jan 11, 2023 ...