222. Count Complete Tree Nodes 223. Rectangle Area 224. Basic Calculator 225. Implement Stack using Queues 226. Invert Binary Tree 227. Basic Calculator II 228. Summary Ranges 229. Majority Element II 23
class Solution { fun firstCompleteIndex(arr: IntArray, mat: Array<IntArray>): Int { val n = mat.size val m = mat[0].size // 计数数组 val rows = IntArray(n) val columns = IntArray(m) // 散列表 val hashMap = HashMap<Int, IntArray>() // 预处理 for (i in 0 until n) ...
3421-count-pairs-that-form-a-complete-day-i 3427-special-array-ii 3429-special-array-i 3434-find-the-number-of-distinct-colors-among-the-balls 3447-clear-digits 3455-minimum-length-of-string-after-operations 3463-alternating-groups-i ...
Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times) with the following restrictions: You may not engage in multiple transactions at the same time (ie, you must sell the stock before...
https://leetcode.cn/problems/determine-the-winner-of-a-bowling-game/ 题目描述 给你两个下标从0开始的整数数组player1和player2,分别表示玩家 1 和玩家 2 击中的瓶数。 保龄球比赛由n轮组成,每轮的瓶数恰好为10。 假设玩家在第i轮中击中xi个瓶子。玩家第i轮的价值为: ...
https://leetcode.com/problems/best-time-to-buy-and-sell-stock/ Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most on...猜你喜欢Leetcode---Week 3 链表插入排序 题目 Sort a linked list using inse...
class Solution { fun countCompleteComponents(n: Int, edges: Array<IntArray>): Int { // 建图(邻接表) val graph = Array(n) { mutableListOf<Int>() } for (edge in edges) { graph[edge[0]].add(edge[1]) graph[edge[1]].add(edge[0]) // 无向边 } // 标记数组 val visit = Bool...
LeetCode153https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/ LeetCode154https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/ LeetCode162https://leetcode.com/problems/find-peak-element/ LeetCode167https://leetcode.com/problems/two-sum-ii-input-array-is-so...
0919 Complete Binary Tree Inserter 57.3% Medium 0920 Number of Music Playlists Go 46.5% Hard 0921 Minimum Add to Make Parentheses Valid Go 73.6% Medium 0922 Sort Array By Parity II Go 69.2% Easy 0923 3Sum With Multiplicity Go 35.7% Medium 0924 Minimize Malware Spread Go 42.0% Hard ...
TLDR: You can use the same pattern for solving 90% of DP problems. You can find this DP pattern below. Many people struggle with DP problems. That often happens because of the common misconception that in order to come up with the solution for the DP problem, you should magically discover...