Scarlet Serenade

LeetCode Solutions | 401 - 500

424. Longest Repeating Character Replacement

sliding window

const is_ok = () => j - i + 1 - max(chars_freqs) <= k

426. Convert Binary Search Tree to Sorted Doubly Linked List

inorder traversal

428. Serialize and Deserialize N-ary Tree

bfs with children_size


TODO

445. Add Two Numbers II

Similar with 2. Add Two Numbers; use a stack

448. Find All Numbers Disappeared in an Array

遍历数组,将每个数字交换到它理应出现的位置上,下面情况不用换:

  • 当前数字本就出现在理应的位置上,跳过,不用换。
  • 当前数字理应出现的位置上,已经存在当前数字,跳过,不用换。

再次遍历,如果当前位置没对应正确的数,如上图索引 4、5,则将对应的 5、6 加入 res。

455. Assign Cookies

greedy

460. LFU Cache

TODO

474. Ones and Zeroes

2D backpack

485. Max Consecutive Ones

trivial

487. Max Consecutive Ones II

sliding window

496. Next Greater Element I

monotonic stack + hashmap