1588. Sum of All Odd Length Subarrays
处理当长度为 1 时特殊情况,其他都遍历长度为奇数情况然后求和。
1 | class Solution: |
1592. Rearrange Spaces Between Words
统计空格出现的次数,然后求出平均空格数进行字符串拼接。
1 | class Solution: |
1593. Split a String Into the Max Number of Unique Substrings
回溯法,使用集合记录出现过的字符串。
1 | class Solution: |
814. Binary Tree Pruning
如果叶子节点的左子树和右子树为空且当前值为 0,则将其置为空,递归剪枝。
1 | # Definition for a binary tree node. |
1008. Construct Binary Search Tree from Preorder Traversal
提供先序遍历,构造二叉树,先序遍历的第一个元素是 root 节点,分别遍历之后元素,如果元素比 root 小,则记录到root 左子树中,反之记录到 root 右子树中,递归构造。
1 | # Definition for a binary tree node. |