leetcode討論會

@leetcode-discuss

Public team

Joined on Mar 12, 2023

  • 1025. Divisor Game (<font color=#00B8A3>Easy</font>) 限制 : 1 <= n <= 1000 ### Solution 時間複雜度: $O(N)$ 空間複雜度: $O(1)$ 程式碼:
     Like  Bookmark
  • Zigzag Grid Traversal With Skip (<font color=#00B8A3>Easy</font>) Solution 時間複雜度: 空間複雜度: 程式碼: class Solution { public: vector<int> zigzagTraversal(vector<vector<int>>& grid) { vector<int> results;
     Like  Bookmark
  • 3402. Minimum Operations to Make Columns Strictly Increasing (<font color=#00B8A3>Easy</font>) Solution 要使每一列嚴格遞增,我們需要確保每列中的元素從上到下依次增大。所以我們可以計算每列中需要修改的元素數量,使其符合嚴格遞增的要求。 時間複雜度: $O(N^2)$ 空間複雜度: $O(N)$
     Like  Bookmark
  • 2833. Furthest Point From Origin (<font color=#00B8A3>Easy</font>) 限制 : 1 <= moves.length == n <= 50 moves consists only of characters 'L', 'R' and '_' Solution 就是簡單的計算哪邊數字大,相減之後再加上底線的數量即為答案。 時間複雜度: $O(n)$
     Like  Bookmark
  • 2815. Max Pair Sum in an Array (<font color=#00B8A3>Easy</font>) 限制 : 2 <= nums.length <= 100 1 <= nums[i] <= 10^4 Solution 注意題意是講說,數字的最大位一樣。這樣就可以很簡單解出來了。 時間複雜度: $O(n^2)$
     Like  Bookmark
  • 2810. Faulty Keyboard (<font color=#00B8A3>Easy</font>) 限制 : 104 Solution 時間複雜度: $O(n)$ 空間複雜度: $O(1)$ 程式碼:
     Like  Bookmark
  • tags: BiWeekly Contest 3330. Find the Original Typed String I (<font color=#00B8A3>Easy</font>) 限制 : 1 <= word.length <= 100 word consists only of lowercase English letters. Solution 時間複雜度: $O(n)$
     Like  Bookmark
  • 3345. Smallest Divisible Digit Product I (<font color=#00B8A3>Easy</font>) 限制: 1 <= n <= 100 1 <= t <= 10 Solution 時間複雜度: $O(n)$ 空間複雜度: $O(1)$ 程式碼:
     Like  Bookmark
  • 3318. Find X-Sum of All K-Long Subarrays I (<font color=#00B8A3>Easy</font>) Solution 時間複雜度: O(n) 空間複雜度: O(1) 程式碼: 3319. K-th Largest Perfect Subtree Size in Binary Tree (<font color=#FFC011>Medium</font>) Solution 時間複雜度: 空間複雜度:
     Like  Bookmark
  • 3324. Find the Sequence of Strings Appeared on the Screen (<font color=#FFC011>Medium</font>) Solution 暴力解,就這樣。 時間複雜度: $O(n^2)$ 空間複雜度: $O(n^2)$ 程式碼: class Solution { public:
     Like  Bookmark
  • 3280 Convert Date to Binary (<font color=#00B8A3>Easy</font>) 限制 : 104 ### Solution 時間複雜度: $O(1)$ 空間複雜度: $O(1)$ 程式碼:
     Like  Bookmark
  • 3258. Count Substrings That Satisfy K-Constraint I (<font color=#00B8A3>Easy</font>) 限制 : 1 <= s.length <= 50 1 <= k <= s.length s[i] is either '0' or '1' Solution 這一題要做的事情是看有多少子序列是符合 0的數量<k 或 1的數量 < k 簡單解的話就是暴力解。
     Like  Bookmark
  • 3264. Final Array State After K Multiplication Operations I (<font color=#00B8A3>Easy</font>) 限制 : 1 <= nums.length <= 100 1 <= nums[i] <= 100 1 <= k <= 10 1 <= multiplier <= 5 ### Solution 時間複雜度: $O(N^2)$
     Like  Bookmark
  • 3216. Lexicographically Smallest String After a Swap (<font color=#00B8A3>Easy</font>) 限制 : 2 <= s.length <= 100 s consists only of digits. ### Solution 時間複雜度: $O(n)$ 空間複雜度: $O(1)$ 程式碼:
     Like  Bookmark
  • 3254. Find the Power of K-Size Subarrays I (<font color=#00B8A3>Easy</font>) 限制 : 1 <= n == nums.length <= 500 1 <= nums[i] <= 105 1 <= k <= n ### Solution 時間複雜度: $O(n*k)$ 空間複雜度: $O(n)$
     Like  Bookmark
  • 3099. Harshad Number (<font color=#00B8A3>Easy</font>) 限制 : 1 <= x <= 100 Solution 這題是要把字元拆開再組回去,然後看有沒有跟原數有倍數關係。 時間複雜度: $O(1)$ 空間複雜度: $O(1)$
     Like  Bookmark
  • 3090. Maximum Length Substring With Two Occurrences (<font color=#00B8A3>Easy</font>) 限制 : 2 <= s.length <= 100 s consists only of lowercase English letters. Solution 利用前後夾擊的方式算出最長的序列,有點類似 LCS ,但又不太像。 時間複雜度: $O(n^2)$
     Like  Bookmark
  • 3083. Existence of a Substring in a String and Its Reverse (<font color=#00B8A3>Easy</font>) 限制 : 1 <= s.length <= 100 s consists only of lowercase English letters. Solution 屬於比較爛的雙指針寫法。 時間複雜度: $O(n^2)$
     Like  Bookmark
  • 1143. Longest Common Subsequence(<font color="FFC011">Medium</font>) 限制 : 1 <= text1.length, text2.length <= 1000 text1 and text2 consist of only lowercase English characters. Solution 利用 Dynamic programming 計算最長子序列。 利用前面的結果推後面的結果
     Like  Bookmark
  • 3074. Apple Redistribution into Boxes (<font color=#00B8A3>Easy</font>) 限制 : 1 <= n == apple.length <= 50 1 <= m == capacity.length <= 50 1 <= apple[i], capacity[i] <= 50 Solution 先將所有蘋果加起來,再由最大的籃子開始放,放到蘋果都空了就得到答案。
     Like  Bookmark