Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6b8e4d6

Browse files
authored
feat: add solutions to lc problem: No.3021 (doocs#2277)
No.3021.Alice and Bob Playing Flower Game
1 parent bb0d262 commit 6b8e4d6

File tree

6 files changed

+99
-6
lines changed

6 files changed

+99
-6
lines changed

solution/3000-3099/3021.Alice and Bob Playing Flower Game/README.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,49 @@
5959
<!-- tabs:start -->
6060

6161
```python
62+
class Solution:
63+
def flowerGame(self, n: int, m: int) -> int:
64+
count = (n + 1) // 2
65+
tol = (m + 1) // 2
66+
ecount = n // 2
67+
etol = m // 2
68+
return count * etol + ecount * tol
6269

6370
```
6471

6572
```java
66-
73+
class Solution {
74+
public long flowerGame(int n, int m) {
75+
long count = (n + 1) / 2;
76+
long tol = (m + 1) / 2;
77+
long ecount = n / 2;
78+
long etol = m / 2;
79+
return (count * etol + ecount * tol);
80+
}
81+
}
6782
```
6883

6984
```cpp
70-
85+
class Solution {
86+
public:
87+
long long flowerGame(int n, int m) {
88+
long long count = (n + 1) / 2;
89+
long long tol = (m + 1) / 2;
90+
long long ecount = n / 2;
91+
long long etol = m / 2;
92+
return (count * etol + ecount * tol);
93+
}
94+
};
7195
```
7296
7397
```go
74-
98+
func flowerGame(n int, m int) int64 {
99+
count := int64((n + 1) / 2)
100+
tol := int64((m + 1) / 2)
101+
ecount := int64(n / 2)
102+
etol := int64(m / 2)
103+
return count*etol + ecount*tol
104+
}
75105
```
76106

77107
<!-- tabs:end -->

solution/3000-3099/3021.Alice and Bob Playing Flower Game/README_EN.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,49 @@
5555
<!-- tabs:start -->
5656

5757
```python
58+
class Solution:
59+
def flowerGame(self, n: int, m: int) -> int:
60+
count = (n + 1) // 2
61+
tol = (m + 1) // 2
62+
ecount = n // 2
63+
etol = m // 2
64+
return count * etol + ecount * tol
5865

5966
```
6067

6168
```java
62-
69+
class Solution {
70+
public long flowerGame(int n, int m) {
71+
long count = (n + 1) / 2;
72+
long tol = (m + 1) / 2;
73+
long ecount = n / 2;
74+
long etol = m / 2;
75+
return (count * etol + ecount * tol);
76+
}
77+
}
6378
```
6479

6580
```cpp
66-
81+
class Solution {
82+
public:
83+
long long flowerGame(int n, int m) {
84+
long long count = (n + 1) / 2;
85+
long long tol = (m + 1) / 2;
86+
long long ecount = n / 2;
87+
long long etol = m / 2;
88+
return (count * etol + ecount * tol);
89+
}
90+
};
6791
```
6892
6993
```go
70-
94+
func flowerGame(n int, m int) int64 {
95+
count := int64((n + 1) / 2)
96+
tol := int64((m + 1) / 2)
97+
ecount := int64(n / 2)
98+
etol := int64(m / 2)
99+
return count*etol + ecount*tol
100+
}
71101
```
72102

73103
<!-- tabs:end -->
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution {
2+
public:
3+
long long flowerGame(int n, int m) {
4+
long long count = (n + 1) / 2;
5+
long long tol = (m + 1) / 2;
6+
long long ecount = n / 2;
7+
long long etol = m / 2;
8+
return (count * etol + ecount * tol);
9+
}
10+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
func flowerGame(n int, m int) int64 {
2+
count := int64((n + 1) / 2)
3+
tol := int64((m + 1) / 2)
4+
ecount := int64(n / 2)
5+
etol := int64(m / 2)
6+
return count*etol + ecount*tol
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution {
2+
public long flowerGame(int n, int m) {
3+
long count = (n + 1) / 2;
4+
long tol = (m + 1) / 2;
5+
long ecount = n / 2;
6+
long etol = m / 2;
7+
return (count * etol + ecount * tol);
8+
}
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution:
2+
def flowerGame(self, n: int, m: int) -> int:
3+
count = (n + 1) // 2
4+
tol = (m + 1) // 2
5+
ecount = n // 2
6+
etol = m // 2
7+
return count * etol + ecount * tol

0 commit comments

Comments
 (0)