Skip to content

Commit a949a02

Browse files
committed
feat: add solutions to lc problem: No.2481
No.2481.Minimum Cuts to Divide a Circle
1 parent b65406c commit a949a02

File tree

5 files changed

+58
-5
lines changed

5 files changed

+58
-5
lines changed

solution/2400-2499/2481.Minimum Cuts to Divide a Circle/README.md

+28-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@
6363
- 当 $n$ 为奇数时,不存在共线的情况,返回 $n$;
6464
- 当 $n$ 为偶数时,可以两两共线,返回 $\frac{n}{2}$。
6565

66+
综上,可以得到:
67+
68+
$$
69+
\text{ans} = \begin{cases}
70+
n, & n \gt 1 \text{ 且 } n \text{ 为奇数} \\
71+
\frac{n}{2}, & n \text{ 为其它} \\
72+
\end{cases}
73+
$$
74+
6675
时间复杂度 $O(1)$,空间复杂度 $O(1)$。
6776

6877
<!-- tabs:start -->
@@ -74,7 +83,7 @@
7483
```python
7584
class Solution:
7685
def numberOfCuts(self, n: int) -> int:
77-
return n if n > 1 and n % 2 else n >> 1
86+
return n if (n > 1 and n & 1) else n >> 1
7887
```
7988

8089
### **Java**
@@ -111,6 +120,24 @@ func numberOfCuts(n int) int {
111120
}
112121
```
113122

123+
### **TypeScript**
124+
125+
```ts
126+
function numberOfCuts(n: number): number {
127+
return n > 1 && n & 1 ? n : n >> 1;
128+
}
129+
```
130+
131+
### **C#**
132+
133+
```cs
134+
public class Solution {
135+
public int NumberOfCuts(int n) {
136+
return n > 1 && n % 2 == 1 ? n : n >> 1;
137+
}
138+
}
139+
```
140+
114141
### **...**
115142

116143
```

solution/2400-2499/2481.Minimum Cuts to Divide a Circle/README_EN.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Also note that the first cut will not divide the circle into distinct parts.
5252
```python
5353
class Solution:
5454
def numberOfCuts(self, n: int) -> int:
55-
return n if n > 1 and n % 2 else n >> 1
55+
return n if (n > 1 and n & 1) else n >> 1
5656
```
5757

5858
### **Java**
@@ -87,6 +87,24 @@ func numberOfCuts(n int) int {
8787
}
8888
```
8989

90+
### **TypeScript**
91+
92+
```ts
93+
function numberOfCuts(n: number): number {
94+
return n > 1 && n & 1 ? n : n >> 1;
95+
}
96+
```
97+
98+
### **C#**
99+
100+
```cs
101+
public class Solution {
102+
public int NumberOfCuts(int n) {
103+
return n > 1 && n % 2 == 1 ? n : n >> 1;
104+
}
105+
}
106+
```
107+
90108
### **...**
91109

92110
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class Solution {
2+
public int NumberOfCuts(int n) {
3+
return n > 1 && n % 2 == 1 ? n : n >> 1;
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
class Solution:
2-
def numberOfCuts(self, n: int) -> int:
3-
return n if n > 1 and n % 2 else n >> 1
1+
class Solution:
2+
def numberOfCuts(self, n: int) -> int:
3+
return n if (n > 1 and n & 1) else n >> 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function numberOfCuts(n: number): number {
2+
return n > 1 && n & 1 ? n : n >> 1;
3+
}

0 commit comments

Comments
 (0)