Try   HackMD

lee215在leetcode論壇上,有關題目的post

Prefix Problems

Problems 心得
2281. Sum of Total Strength of Wizards
1074. Number of Submatrices That Sum to Target 怎麼利用prefix sum把
O(N4)
變成
O(N3)
解法
974. Subarray Sums Divisible by K 怎麼處理prefix sum 為負的情況?解法
  • Prefix Sum的問題都必須注意,使用hash table必須有 sum = 0這個element。
unordered_map<int, int> m{{0, 1}};

Sliding Window Problems

Problems 心得
2958. Length of Longest Subarray With at Most K Frequency 使用unordered_map<int, int>來統計數字出現的次數
2831. Find the Longest Equal Subarray
2799. Count Complete Subarrays in an Array 滿足條件後,計算subarray的方法
ans += nums.size() - right;
2779. Maximum Beauty of an Array After Applying Operation
930. Binary Subarrays With Sum 可以用prefix sum來解
使用slinding window就必須要用 atMost(goal) - atMost(goal - 1)
992. Subarrays with K Different Integers
904. Fruit Into Baskets
862. Shortest Subarray with Sum at Least K
424. Longest Repeating Character Replacement
209. Minimum Size Subarray Sum 使用slinding window來追蹤sum的大小

Stack Problems

Problems 心得
2735. Collecting Chocolates
2594. Minimum Time to Repair Cars
2454. Next Greater Element IV
901. Online Stock Span
856. Score of Parentheses
503. Next Greater Element II 把array循環兩次

Mono Stack Problem

Problems 心得
2866. Beautiful Towers II
2454. Next Greater Element IV
2398. Maximum Number of Robots Within Budget

Binary Search Problems

Problems 心得
2616. Minimize the Maximum Difference of Pairs
2560. House Robber IV
2226. Maximum Candies Allocated to K Children 使用可以分出最大數的堆數
875. Koko Eating Bananas 使用binary search找出答案
774. Minimize Max Distance to Gas Station
410. Split Array Largest Sum

DP problems

Problems 心得
2920. Maximum Points After Collecting Coins From All Nodes
2919. Minimum Increment Operations to Make Array Beautiful
2896. Apply Operations to Make Two Strings Equal
2830. Maximize the Profit as the Salesman
2008. Maximum Earnings From Taxi
1751. Maximum Number of Events That Can Be Attended II
1235. Maximum Profit in Job Scheduling