2024-04-09 解題區►Leetcode►Easy Leetcode 2073 - Time Needed to Buy Tickets 題目 Problem# 有 $n$ 個人排隊買票,每個人想買 tickets[i] 張票,每次買票要花一秒鐘,問你第 $k$ 個人買完票的時候,總共花了幾秒? 測資限制# n = tickets.size() $1 \le n \le 100$ m = tickets[i] $1 \le m \le 100$ $0 \le k < n$ Read More
2024-04-07 解題區►Leetcode►Medium Leetcode 678 - Valid Parenthesis String 題目 Problem# 給你一個字串 s 其中只包含三種字元: (, ), *,所有的括號必須左右匹配,右括號必須在左括號後面,星號可以變成左、右括號、或空字串,回傳字串 s 是否合法。 測資限制# $1 \le n \le 100$ Read More
2024-03-25 解題區►Leetcode►Medium Leetcode 287 - Find the Duplicate Number 題目 Problem# 給你一個整數陣列 nums 包含 $n+1$ 個整數,值域 $[1, n]$,陣列裡面只包含一個重複的數字,找出這個重複的數字並回傳。 限制: 不能修改原本的陣列,且空間複雜度必須在 $O(1)$ Follow up: 證明陣列裡面只包含一個重複的數字的正確性? 解在 $O(n)$ 時間複雜度內 測資限制# Read More
2024-03-21 解題區►Leetcode►Easy Leetcode 206 - Reverse Linked List 題目 Problem# 給你一個單向 linked-list head 叫你把它反轉 Follow-up: recursively 和 iteratively 都要實作一次 Read More
2024-03-20 解題區►Leetcode►Medium Leetcode 1669 - Merge In Between Linked Lists 題目 Problem# 給你兩個 linked-list A 和 B 長度分別是 n 和 m,並給你兩個正整數 a 和 b 代表要從 A 中移除第 a 個到第 b 個 node,之後用 B 替代,要你回傳替代後的結果。 測資限制# Read More
2024-03-15 解題區►Leetcode►Medium Leetcode 238 - Product of Array Except Self 題目 Problem# 給你一個整數陣列 nums,要你回傳答案陣列 answer[i] = nums[0] * ... * nums[i-1] * nums[i+1] * ... * nums[n-1] (也就是除了 nums[i] 之外的相乘) 時間複雜度必須在 $O(n)$。 測資限制# $2 \le n \le 10^5$ $-30 \le val \le 30$ Read More
2024-03-13 解題區►Leetcode►Easy Leetcode 2485 - Find the Pivot Integer 題目 Problem# 給你正整數 $n$ 要你找到 pivot $i$ 使得 $1+2+\cdots +i = i + (i+1) + (i+2) + \cdots + n$,如果找不到則回傳 -1 測資限制# $1 \le n \le 1000$ Read More
2024-03-11 解題區►Leetcode►Medium Leetcode 791 - Custom Sort String 題目 Problem# 給你兩個字串 order 和 s,要你把 s 按照 order 的字母順序排序,沒出現在裡面的字母位置隨意,回傳排序後的字串。 測資限制# $1 \le \text{order} \le 26$ $1 \le \text{s} \le 200$ Read More
2024-03-03 解題區►Leetcode►Medium Leetcode 3067 - Count Pairs of Connectable Servers in a Weighted Tree Network 題目 Problem# 給你一個有 $n$ 個點的無向圖,另外給你一個整數 ss。 定義點 a 與點 b 之間是否是透過點 c 連接的,必須符合以下條件: Read More
2024-03-01 解題區►Leetcode►Easy Leetcode 2864 - Maximum Odd Binary Number 題目 Problem# 給你只有 0 和 1 (至少包含一個) 的字串 s ,你可以將 bit 自由交換位置,問你最大的奇數是多少? 測資限制# $1 \le n \le 100$ Read More