leetcode-1259-Handshakes That Don't Cross
问题
You are given an even number of people num_people
that stand around a circle and each person shakes hands with someone else, so that there are num_people / 2
handshakes total.
Return the number of ways these handshakes could occur such that none of the handshakes cross.
Since this number could be very big, return the answer mod 10^9 + 7
Example 1:
1 | Input: num_people = 2 |
Example 2:
1 | Input: num_people = 4 |
Example 3:
1 | Input: num_people = 6 |
Example 4:
1 | Input: num_people = 8 |
Constraints:
2 <= num_people <= 1000
num_people % 2 == 0
分析
思路1: 动态规划
思路2: 卡特兰数
代码1
1 | class Solution { |
代码2
1 | int numberOfWays(int n) { |
Author: Hatton.Liu
Link: http://hattonl.github.io/2020/04/02/leetcode-1259/
License: 知识共享署名-非商业性使用 4.0 国际许可协议