2023-11-22 解題區►Leetcode►Medium Leetcode 1424 - Diagonal Traverse II 題目 Problem# 給你一個二維的整數陣列 nums 問你能不能照對角順序輸出(左下到右上)。 測資限制# Read More
2023-11-16 解題區►Leetcode►Medium Leetcode 1980 - Find Unique Binary String 題目 Problem# 給你 $n$ 個 binary string nums,其中每個 string 長度 $n$,要你回傳沒有出現在 nums 裏頭的 binary string。 測資限制# $1 \le n \le 16$ Read More
2023-11-15 解題區►Leetcode►Medium Leetcode 1846 - Maximum Element After Decreasing and Rearranging 題目 Problem# 給你一個正整數陣列 arr 問你能不能透過以下兩種操作變換成 [1,2,3,...,i-1, i] 的遞增形式: 對 arr[i] 減一,不能小於等於零 排列 arr[i] 以上操作可以做任意次,問經過操作後 arr 滿足遞增形式的數字最多有幾個? 測資限制# Read More
2023-11-13 解題區►Leetcode►Medium Leetcode 2785 - Sort Vowels in a String 題目 Problem# 給你一個字串 s 要你照規則排成新的字串 t 並輸出: 所有子音的字母保留原位 所有母音照遞增排序 測資限制# Read More
2023-11-12 解題區►Leetcode►Hard Leetcode 2642 - Design Graph With Shortest Path Calculator 題目 Problem# 有一個有向帶權圖有 $n$ 個節點標號從 0 到 n-1,要你實作一個 Graph class 可以輸入一張圖,包含 n 個點和 edges 邊,並且能提供求點 a 到點 b 的最短路徑,並且能隨時加邊。 要實作三個 function: Read More
2023-11-11 解題區►Leetcode►Medium Leetcode 1743 - Restore the Array From Adjacent Pairs 題目 Problem# 有一個整數陣列 nums 裏頭有 $n$ 個 unique 的元素。題目給你一個 adjacentPairs[i] = [ui, vi] 陣列有 $n-1$ 個元素,代表 ui 與 vi 在 nums 相鄰。保證所有 nums 相鄰的數字一定出現在 adjacentPairs 中,可能以任意順序出現。 回傳原始的 nums 陣列,如果有多種解,回傳任意一種。 測資限制# nums 長度: $2 \le n \le 10^5$ adjacentPairs 長度: $== n-1$ $-10^5 \le \text{nums[i]}, u_i, v_i \le 10^5$ Read More
2023-11-09 解題區►Leetcode►Medium Leetcode 1759 - Count Number of Homogenous Substrings 題目 Problem# 給你一個字串 s 要你回傳所有 homogeneous 的子字串的個數總和。homogenous 指的是字串裡的所有字元都一樣。 答案可能很大要 mod $10^9+7$ 測資限制# $1 \le n \le 10^5$ Read More
2023-11-05 解題區►Leetcode►Medium Leetcode 1535 - Find the Winner of an Array Game 題目 Problem# 給你一個數字不重複的整數陣列 arr 和一個整數 k,每次比較陣列第一個(arr[0])與第二個元素(arr[1])的大小,贏的數字會在 index 0,輸的數字則移動到 arr 的最後,其他數字依序往前移動一格。當有個數字連續贏 k 場時比賽結束,回傳贏的數字。 測資限制# $2 \le \text{len(arr)} \le 10^5$ $1 \le \text{arr[i]} \le 10^6$ $1 \le k \le 10^9$ 保證每場比賽一定會有贏者 Read More
2023-11-05 解題區►Leetcode►Medium Leetcode 1503 - Last Moment Before All Ants Fall Out of a Plank 題目 Problem# 木棍長 n 個單位,上頭有一群螞蟻在走,各自朝著左方與右方,每秒移動一個單位。每當螞蟻相遇時,會各自往反方向走。當螞蟻走出 0 或 n 時會掉出去,給你朝左與朝右的螞蟻初始位置,問你經過幾秒後,所有螞蟻都掉出木棍? 測資限制# $1 \le n \le 10^4$ Read More
2023-11-03 解題區►Leetcode►Medium Leetcode 1441 - Build an Array With Stack Operations 題目 Problem# 你有一個 stack 並可以對他做兩個操作:Push, Pop 給你一個整數陣列 target 和整數 n ,你有 [1, n] 數字,每次 Push 數字都會加一,問你能不能給出一組操作,使得 stack 的元素等於 target? 測資限制# Read More