Leetcode 題型分類與解題方向

分享
AI coding
AI coding

我發現這些 leetcode 好像依照不同的題型會有類似的解法,所以請 AI 幫我統整每一個種類題型的解題方向。大致上可以分成 9 種類型,如果遇到這類型可以先往每個類別中列出的解題方法來思考,在這裡做個紀錄

1. Array Problems

  • Two Pointers: Used for problems like finding pairs, subarrays, or for partitioning arrays.
    • Example: 283 (Move Zeroes), 11 (Container With Most Water).
  • Sorting: Often needed before applying binary search or two-pointer techniques.
    • Example: 56 (Merge Intervals).
  • Binary Search: For finding specific elements or ranges in a sorted array.
    • Example: 34 (Find First and Last Position of Element).

2. String Problems

  • Sliding Window: Useful for finding the longest substring with certain properties.
    • Example: 3 (Longest Substring Without Repeating Characters).
  • HashMap/HashSet: For character frequency counts or to check for unique characters.
    • Example: 387 (First Unique Character in a String).

3. Linked List Problems

  • Fast and Slow Pointers: For detecting cycles or finding the middle of the list.
    • Example: 141 (Linked List Cycle), 19 (Remove Nth Node From End of List).
  • Reversing a Linked List: Important for palindrome checks or simply reversing the list.
    • Example: 206 (Reverse Linked List).

4. Tree/Graph Problems

  • Depth-First Search (DFS): For traversing nodes and backtracking.
    • Example: 104 (Maximum Depth of Binary Tree), 17 (Letter Combinations of a Phone Number).
  • Breadth-First Search (BFS): Useful for finding the shortest path or level order traversal.
    • Example: 102 (Binary Tree Level Order Traversal).
  • Dynamic Programming on Trees: For problems like finding the maximum path sum.
    • Example: 124 (Binary Tree Maximum Path Sum).

5. Dynamic Programming

  • Knapsack Problems: Problems related to finding the optimal subset.
    • Example: 322 (Coin Change).
  • Fibonacci Sequence: Used in problems like climbing stairs or house robbing.
    • Example: 70 (Climbing Stairs), 198 (House Robber).
  • Grid DP: For pathfinding in grids (e.g., unique paths, minimum path sum).
    • Example: 62 (Unique Paths).

6. Backtracking

  • Generating Combinations/Permutations: Used when you need to explore all possibilities.
    • Example: 22 (Generate Parentheses), 39 (Combination Sum).
  • Pruning: Often, you can optimize backtracking by skipping unnecessary paths.
    • Example: 51 (N-Queens).

7. Greedy Algorithms

  • Interval Scheduling: Choosing the best option at each step for problems like merging intervals.
    • Example: 452 (Minimum Number of Arrows to Burst Balloons).
  • Coin Change Problem: Choosing the largest denomination first.
    • Example: 455 (Assign Cookies).

8. Bit Manipulation

  • XOR Operations: Commonly used in problems involving pairs or unique elements.
    • Example: 136 (Single Number).
  • Bitwise Shifts: Useful for checking or setting specific bits.
    • Example: 190 (Reverse Bits).

9. Math Problems

  • Number Theory: Problems involving prime numbers, GCD/LCM, or modulo operations.
    • Example: 50 (Pow(x, n)), 326 (Power of Three).
  • Simulation: Simulating the process described in the problem.
    • Example: 415 (Add Strings), 29 (Divide Two Integers).
AI 建議:

By recognizing these patterns, you can often apply similar strategies across different problems, making it easier to solve new ones. If you'd like a deeper dive into any of these categories or specific problem examples, feel free to ask!

Read more

Gaze Guard 短影片旁白的 TTS 成本與隱私防護示意圖

短影片旁白的成本,其實比我想像低

我最近在做一支 Gaze Guard 的 20 秒產品介紹影片。 原本想說簡單做個動畫就好。 後來想說如果有配音,會感覺比較生動也比較能夠描述使用的情境和達成的效果。 這次我測了什麼 我測的是產品介紹影片用的英文旁白。 工具底層使用的是 Edge TTS,也就是 Microsoft Edge 的線上 Text-to-Speech 服務。常見的底層工具是 edge-tts。 這不是正式 Azure Speech API 的計費路徑。 在我這次的環境裡,它沒有要求 API key,也沒有回傳可見的 per-use billing。 所以這次測試本身,比較像是快速 prototype。 如果未來要正式商用、穩定大量產出,就要回頭看 Azure Speech、OpenAI TTS、ElevenLabs 這類正式付費方案。

By SteepingLogic
用 Cloudflare Tunnel,從外面連回本機 Hermes Dashboard

用 Cloudflare Tunnel,從外面連回本機 Hermes Dashboard

# 用 Cloudflare Tunnel,從外面連回本機 Hermes Dashboard 我有一台 local Hermes。 平常它就在自己的機器上跑。 可能是家裡的桌機。 可能是 NAS。 可能是一台一直開著的 Linux box。 也可能只是我自己的筆電。 問題是,人一離開那個網路,Hermes dashboard 就變成一個只存在於 localhost 的東西。 我想在外面打開它。 但我沒有 static IP。 沒有買網域。 也不想進路由器開 port forwarding。 因為那條路通常長這樣: * 找 public IP * 設定 NAT * 開 port * 處理防火牆 * 補 HTTPS * 設定憑證 * 再擔心 origin IP 被掃 非常友善。 所以這篇先走另一條路:

By SteepingLogic
Invoshot 開發日記|正向回饋

Invoshot 開發日記|正向回饋

想信很多人在開發的時候都常常會做一件事,那就是: 不斷地反覆思考,在腦袋內把流程跑過很多次,然後思考哪裡可以做得更好 不限坐在電腦前的時後,可能是在捷運上,在人行道上, 在馬桶上或是在洗澡的時候 🤪 我不斷地在想:AI 辨識完一張發票後,使用者接下來最需要的是什麼? 每個欄位都要核對嗎? 這麼多欄位真的不會漏看嗎? 所以我在 Invoshot 裡加了提醒功能。 辨識結果出來後,系統會把比較需要注意的地方標出來。 不是把所有不確定都丟給使用者,而是把他真正需要介入的那幾秒鐘留出來。 今天收到一則訊息: 今天用了有新增提醒功能很棒! 真的有變輕鬆 😎 看到這句的時候,我第一個想到的是: 原來那些只是我腦內風暴的優化項目,使用者是真的可以感受到差異的! 感覺又有動力了!

By SteepingLogic