原创 【並查集】B011_LC_交換字符串中的元素(Map + PQ)

一、Problem You are given a string s, and an array of pairs of indices in the string pairs where pairs[i] = [a, b] in

原创 【網格 dp】B004_LC_下降路徑最小和 I(邊界判斷)

一、Problem Given a square array of integers A, we want the minimum sum of a falling path through A. A falling path s

原创 【數組】C077_LC_二維網格遷移(模擬 / 雙端隊列)

一、Problem Given a 2D grid of size m x n and an integer k. You need to shift the grid k times. In one shift operatio

原创 【搜索】A062_LC_推箱子(雙端隊列 bfs(代辦))

一、Problem Storekeeper is a game in which the player pushes boxes around in a warehouse trying to get them to target

原创 【區間 dp】A014_LC_安排郵筒(麻煩的邊界)

一、Problem Given the array houses and an integer k. where houses[i] is the location of the ith house along a street,

原创 【前綴和】B003_LC_找兩個和爲目標值且不重疊的子數組(記錄前綴和下標)

一、Problem Given an array of integers arr and an integer target. You have to find two non-overlapping sub-arrays of

原创 【設計】B005_LC_點菜展示表(Map + TreeSet)

一、Problem 給你一個數組 orders,表示客戶在餐廳中完成的訂單,確切地說, orders[i]=[customerNamei,tableNumberi,foodItemi] ,其中 customerNamei 是客戶的

原创 【二分】B016_LC_製作 m 束花所需的最少天數(枚舉時檢查)

一、Problem Given an integer array bloomDay, an integer m and an integer k. We need to make m bouquets. To make a bou

原创 【線性 dp】B006_LC_可被三整除的最大和(三種餘數)

一、Problem Given an array nums of integers, we need to find the maximum possible sum of elements of the array such t

原创 【設計】B004_LC_搜索推薦系統(排序 / Trie + count(代辦))

一、Problem Given an array of strings products and a string searchWord. We want to design a system that suggests at m

原创 【貪心】B041_LC_用戶分組(map + 反向思維)

一、Problem There are n people whose IDs go from 0 to n - 1 and each person belongs exactly to one group. Given the a

原创 【遞推型 dp】B003_LC_停在原地的方案數(記憶化 / dp)

一、Problem You have a pointer at index 0 in an array of size arrLen. At each step, you can move 1 position to the le

原创 【模板】B000_JM_子矩陣的和、差分(二維前綴和 / 一維差分)

一、子矩陣的和 輸入一個 n 行 m 列的整數矩陣,再輸入 q 個詢問,每個詢問包含四個整數 x1,y1,x2,y2,表示一個子矩陣的左上角座標和右下角座標。 對於每個詢問輸出子矩陣中所有數的和。 Input 第一行包含三個整數

原创 【遞推型 dp】C002_LC1_柵欄染色(爬樓梯變形 / 滾動壓縮)

一、Problem 我們有一個柵欄,它有n個柱子,現在要給柱子染色,有k種顏色可以染。 必須保證不存在超過2個相鄰的柱子顏色相同,求有多少種染色方案。 輸入: n=3, k=2 輸出: 6 Explanation:

原创 【網格 dp】C003_LC_下降路徑最小和 II(dp)

一、Problem Given a square grid of integers arr, a falling path with non-zero shifts is a choice of exactly one eleme