LeetCode101: 3. Longest Substring Without Repeating Characters

tags: Sliding Window,LeetCode101,Hash Table Use HashMap to store counts of letters Two points we should be noticed: The length of substring should be (right - left) + 1, as one side must be counted. We must decrese the number in the counts first, and then slide the left window, or we must decrese the wrong one, please compare between Wrong and Correct. Wrong left++; counts[s[left]]--; Correct counts[s[left]]--; left++; The full code see: ...

March 11, 2022 · 3 min · Gray King

Sliding Window

tags: Algorithm Slide right to move forward to find the solution. Slide left to keep the solution, and collect to the results. Must avoid left go to backward.

March 11, 2022 · 1 min · Gray King

445. Add Two Numbers II

March 11, 2022 · 0 min · Gray King

LeetCode101: 445. Add Two Numbers II

tags: Linked List,Stack, LeetCode101,2. Add Two Numbers 两数之和的进阶版,位高的数字在链表的头部,常规解法是通过「栈」进行反转链表,然后回退到2. Add Two Numbers的解法。

March 11, 2022 · 1 min · Gray King

Stack

tags: Data Structures

March 11, 2022 · 1 min · Gray King