题目描述:
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.
For example:
Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return ...
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.
For example:
Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return ...
Given a binary tree, return all root-to-leaf paths.
For example, given the following binary tree:
1 / \ 2 3 \ 5
All root-to-leaf paths are:
["1->2->5", "1->3"]
给定一棵二叉树,返回所有“根到叶子”的路径。
例如,给定下面的二叉树:
1 / \ 2 3 \ 5
所有“根到叶子”路径为:
["1->2->5", "1->3"]
树的遍历 ...
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings as shown on ...
让我们通过考虑下面的问题来理解线段树。
给定一个数组arr[0 . . . n-1]
,我们要对数组执行这样的操作:
1 计算从下标l到r的元素之和,其中 0 <= l <= r <= n-1
2 修改数组指定元素的值arr[i] = x,其中 0 <= i <= n-1
一个简单的方案是从l
到r
执行循环,计算给定区间的元素之和。更新值的时候,简单地令arr[i] = x。第一个操作花费O(n)的时间,第二个操作花费O ...
The string "PAYPALISHIRING"
is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)
P A H N A P L S ...