-
The 'intuitive' solution:
```
class Solution {
public int combinationSum4(int[] nums, int target) {
if (nums == null || nums.length == 0) return 0;
if (target == 0) return 1;
…
-
Given an integer array `nums` and an integer `k`, return `true` if it is possible to divide this array into `k` non-empty subsets whose sums are all equal.
Example 1:
Input: nums …
-
Given a binary tree, collect a tree's nodes as if you were doing this: Collect and remove all leaves, repeat until the tree is empty.
Example:
Input: [1,2,3,4,5]
…
-
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.
Return a [deep copy](https://en.wikipedia.org/wiki/Object_copyin…
-
Given a binary search tree, write a function `kthSmallest` to find the kth smallest element in it.
Note:
You may assume k is always valid, 1 ≤ k ≤ BST's total elements.
Example 1:
…
-
[请点击下方图片观看讲解视频](https://www.youtube.com/watch?v=cJdDY4UNTfI)
[Click below image to watch YouTube Video](https://www.youtube.com/watch?v=cJdDY4UNTfI)
[![Video](https://img.youtube.com/vi/cJdDY4UNTfI/0.…
-
Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these N numbers successfully if one of the following is true for the ith position (1 ≤ …
-
There is a ball in a maze with empty spaces and walls. The ball can go through empty spaces by rolling up, down, left or right, but it won't stop rolling until hitting a wall. When the ball stops, …
-
给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按照顺时针螺旋顺序,返回矩阵中的所有元素。
```
示例 1:
输入:
[
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ]
]
输出: [1,2,3,6,9,8,7,4,5]
示例 2:
输入:
[
[1, 2, 3, 4],
[5, 6, 7, 8]…
-
给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。
candidates 中的每个数字在每个组合中只能使用一次。
说明:
所有数字(包括目标数)都是正整数。
解集不能包含重复的组合。
```
示例 1:
输入: candidates = [10,1,2,7,6,1,5], tar…