LEETCODE 1301. Number of Paths with Max Score 解题思路分析

题目大意:

最大得分的路径数目

给你一个正方形字符数组 board ,你从数组最右下方的字符 ‘S’ 出发。

你的目标是到达数组最左上角的字符 ‘E’ ,数组剩余的部分为数字字符 1, 2, …, 9 或者障碍 ‘X’。在每一步移动中,你可以向上、向左或者左上方移动,可以移动的前提是到达的格子没有障碍。

一条路径的 「得分」 定义为:路径上所有数字的和。

请你返回一个列表,包含两个整数:第一个整数是 「得分」 的最大值,第二个整数是得到最大得分的方案数,请把结果对 10^9 + 7 取余。

如果没有任何路径可以到达终点,请返回 [0, 0] 。

继续阅读
发表在 leetcode | 标签为 , , , | 留下评论

LEETCODE 1302. Deepest Leaves Sum 解题思路分析

题目大意:

层数最深叶子节点的和

给你一棵二叉树,请你返回层数最深的叶子节点的和。

继续阅读
发表在 leetcode | 标签为 , , , , | 一条评论

LEETCODE 1304. Find N Unique Integers Sum up to Zero 解题思路分析

题目大意:

和为零的N个唯一整数

给你一个整数 n,请你返回 任意 一个由 n 个 各不相同 的整数组成的数组,并且这 n 个数相加和为 0 。

继续阅读
发表在 leetcode | 标签为 , , | 留下评论

LEETCODE 1305. All Elements in Two Binary Search Trees 解题思路分析

题目大意:

两棵二叉搜索树中的所有元素

给你 root1 和 root2 这两棵二叉搜索树。

请你返回一个列表,其中包含 两棵树 中的所有整数并按 升序 排序。

继续阅读
发表在 leetcode | 标签为 , , , , | 留下评论

LEETCODE 1306. Jump Game III 解题思路分析

题目大意:

跳跃游戏 III

这里有一个非负整数数组 arr,你最开始位于该数组的起始下标 start 处。当你位于下标 i 处时,你可以跳到 i + arr[i] 或者 i – arr[i]。

请你判断自己是否能够跳到对应元素值为 0 的 任意 下标处。

注意,不管是什么情况下,你都无法跳到数组之外。

继续阅读
发表在 leetcode | 标签为 , , | 2条评论

LEETCODE 1307. Verbal Arithmetic Puzzle 解题思路分析

题目大意:

口算难题

给你一个方程,左边用 words 表示,右边用 result 表示。

你需要根据以下规则检查方程是否可解:

  • 每个字符都会被解码成一位数字(0 – 9)。
  • 每对不同的字符必须映射到不同的数字。
  • 每个 words[i] 和 result 都会被解码成一个没有前导零的数字。
  • 左侧数字之和(words)等于右侧数字(result)。 

如果方程可解,返回 True,否则返回 False

继续阅读
发表在 leetcode | 标签为 , , | 留下评论

LEETCODE 1309. Decrypt String from Alphabet to Integer Mapping 解题思路分析

题目大意:

解码字母到整数映射

给你一个字符串 s,它由数字('0' – '9')和 '#' 组成。我们希望按下述规则将 s 映射为一些小写英文字符:

  • 字符('a' – 'i')分别用('1' – '9')表示。
  • 字符('j' – 'z')分别用('10#' – '26#')表示。 

返回映射之后形成的新字符串。

题目数据保证映射始终唯一。

继续阅读
发表在 leetcode | 标签为 , , | 留下评论

LEETCODE 582. Kill Process 解题思路分析

题目大意:

杀死进程

Given n processes, each process has a unique PID (process id) and its PPID (parent process id).

Each process only has one parent process, but may have one or more children processes. This is just like a tree structure. Only one process has PPID that is 0, which means this process has no parent process. All the PIDs will be distinct positive integers.

We use two list of integers to represent a list of processes, where the first list contains PID for each process and the second list contains the corresponding PPID.

Now given the two lists, and a PID representing a process you want to kill, return a list of PIDs of processes that will be killed in the end. You should assume that when a process is killed, all its children processes will be killed. No order is required for the final answer.

继续阅读
发表在 leetcode | 标签为 , , , | 留下评论

LEETCODE 984. String Without AAA or BBB 解题思路分析

题目大意:

不含 AAA 或 BBB 的字符串

给定两个整数 A 和 B,返回任意字符串 S,要求满足:

  • S 的长度为 A + B,且正好包含 A 个 ‘a’ 字母与 B 个 ‘b’ 字母;
  • 子串 ‘aaa’ 没有出现在 S 中;
  • 子串 ‘bbb’ 没有出现在 S 中。
继续阅读
发表在 leetcode | 标签为 , , , | 留下评论

LEETCODE 606. Construct String from Binary Tree 解题思路分析

题目大意:

根据二叉树创建字符串

你需要采用前序遍历的方式,将一个二叉树转换成一个由括号和整数组成的字符串。

空节点则用一对空括号 “()” 表示。而且你需要省略所有不影响字符串与原始二叉树之间的一对一映射关系的空括号对。

继续阅读
发表在 leetcode | 标签为 , , , | 留下评论