LeetCode 题解工作台
分割圆的最少切割次数
圆内一个 有效切割 ,符合以下二者之一: 该切割是两个端点在圆上的线段,且该线段经过圆心。 该切割是一端在圆心另一端在圆上的线段。 一些有效和无效的切割如下图所示。 给你一个整数 n ,请你返回将圆切割成相等的 n 等分的 最少 切割次数。 示例 1: 输入: n = 4 输出: 2 解释: 上图展…
2
题型
7
代码语言
3
相关题
当前训练重点
简单 · 数学·结合·几何
答案摘要
- 当 时,不需要切割,即切割次数为 ; - 当 为奇数时,不存在共线的情况,最少需要 次切割;
Interview AiBoxInterview AiBox 实时 AI 助手,陪你讲清 数学·结合·几何 题型思路
题目描述
圆内一个 有效切割 ,符合以下二者之一:
- 该切割是两个端点在圆上的线段,且该线段经过圆心。
- 该切割是一端在圆心另一端在圆上的线段。
一些有效和无效的切割如下图所示。

给你一个整数 n ,请你返回将圆切割成相等的 n 等分的 最少 切割次数。
示例 1:

输入:n = 4 输出:2 解释: 上图展示了切割圆 2 次,得到四等分。
示例 2:

输入:n = 3 输出:3 解释: 最少需要切割 3 次,将圆切成三等分。 少于 3 次切割无法将圆切成大小相等面积相同的 3 等分。 同时可以观察到,第一次切割无法将圆切割开。
提示:
1 <= n <= 100
解题思路
方法一:分类讨论
- 当 时,不需要切割,即切割次数为 ;
- 当 为奇数时,不存在共线的情况,最少需要 次切割;
- 当 为偶数时,可以两两共线,最少需要 次切割。
综上,可以得到:
时间复杂度 ,空间复杂度 。
class Solution:
def numberOfCuts(self, n: int) -> int:
return n if (n > 1 and n & 1) else n >> 1
复杂度分析
| 指标 | 值 |
|---|---|
| 时间 | complexity is O(1) because the solution is a single conditional check based on parity. Space complexity is O(1) as no extra data structures are needed. |
| 空间 | Depends on the final approach |
面试官常问的追问
外企场景- question_mark
Asks for the minimum number of cuts for small n like 4 or 5.
- question_mark
Hints at separating odd and even n to reduce overcutting.
- question_mark
Checks if candidate can explain why fewer cuts fail for odd n.
常见陷阱
外企场景- error
Assuming each cut always doubles slices, which fails for odd n.
- error
Ignoring the center-cross requirement, leading to invalid slices.
- error
Confusing minimum number of cuts with total slices created.
进阶变体
外企场景- arrow_right_alt
Determine cuts if slices must be non-overlapping sectors of different sizes.
- arrow_right_alt
Find minimum cuts for a circle with concentric rings instead of one layer.
- arrow_right_alt
Calculate cuts if the circle can only be cut along specific angles.