Skip to content

Commit a2df20d

Browse files
authored
Create 3021-alice-and-bob-playing-flower-game.java
1 parent 558c9e3 commit a2df20d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// LeetCode Problem: 3021. Alice and Bob Playing Flower Game
2+
// https://leetcode.com/problems/alice-and-bob-playing-flower-game/
3+
//
4+
// Description:
5+
// Alice and Bob have flowers in a garden. Alice has n flowers and Bob has m flowers.
6+
// They play a game where in each round, they both pick one flower each. If the sum of
7+
// the number of petals of their flowers is odd, Alice wins. Otherwise, Bob wins.
8+
// Return the total number of rounds where Alice wins.
9+
//
10+
// Example 1:
11+
// Input: n = 3, m = 2
12+
// Output: 3
13+
//
14+
// Example 2:
15+
// Input: n = 1, m = 1
16+
// Output: 0
17+
//
18+
// Constraints:
19+
// 1 <= n, m <= 10^5
20+
21+
class Solution {
22+
public long flowerGame(int n, int m) {
23+
return (long) n * m / 2;
24+
}
25+
}
26+
27+
// For local testing
28+
class Main {
29+
public static void main(String[] args) {
30+
Solution sol = new Solution();
31+
32+
System.out.println(sol.flowerGame(3, 2)); // Expected: 3
33+
System.out.println(sol.flowerGame(1, 1)); // Expected: 0
34+
System.out.println(sol.flowerGame(5, 4)); // Quick check
35+
}
36+
}

0 commit comments

Comments
 (0)