2023-11-28 解題區►Leetcode►Medium Leetcode 935 - Knight Dialer 題目 Problem# 你能操縱一個西洋棋的騎士(Knight)旗子,它只能走 L 字形。 Read More
2023-11-25 解題區►Leetcode►Medium Leetcode 1685 - Sum of Absolute Differences in a Sorted Array 題目 Problem# 給你一個遞減排序的整數陣列 nums ,要你回傳另一個整數陣列 result[i] 代表 nums[i] 與 nums 裡的所有數字的差距的絕對值總和。 result[i] = sum(|nums[i]-nums[j]|) where 0 <= j < nums.length && j != i 測資限制# 2≤n≤105 1≤nums[i]≤nums[i+1]≤104 Read More
2023-11-24 解題區►Leetcode►Medium Leetcode 1561 - Maximum Number of Coins You Can Get 題目 Problem# 你有 3n 個堆錢,有三個人參加遊戲,每次你先挑三堆錢,接著 B 拿最大的,接著換你拿最大的,剩下的 C 拿。 一直這樣持續直到所有錢都分完,問你最大能拿多少錢? 測資限制# 幾堆錢: 3≤n≤105 每堆錢數量: 1≤val≤104 Read More
2023-11-23 解題區►Leetcode►Medium Leetcode 1630 - Arithmetic Subarrays 題目 Problem# 給你一個整數陣列 nums,如果可以重排成: 其中的整個陣列的相鄰數字的差(s[i+1] - s[i] == s[1] - s[0])相同的話代表 true 反之代表 false。 還有兩個整數陣列 L 和 R,其中 [L[i], R[i]] 代表查詢 nums 中 index 範圍的數字是 true 還 false,會把答案存在陣列並回傳。 測資限制# nums 大小: 2≤n≤500 L, R 大小: 1≤m≤500 0≤L[i]<R[i]<n −105≤nums[i]≤105 Read More
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≤n≤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≤n≤105 adjacentPairs 長度: ==n−1 −105≤nums[i],ui,vi≤105 Read More