diff options
-rw-r--r-- | alice_bob_flower_game.c | 17 | ||||
-rw-r--r-- | alice_bob_flower_game.py | 25 |
2 files changed, 42 insertions, 0 deletions
diff --git a/alice_bob_flower_game.c b/alice_bob_flower_game.c new file mode 100644 index 0000000..efe9866 --- /dev/null +++ b/alice_bob_flower_game.c @@ -0,0 +1,17 @@ +// 3021. Alice and Bob Playing Flower Game +#include "leetcode.h" + +/* + * alice and bob are playing a turn-based game on a field with two lanes of + * flowers bet=een them. there are 'x' flowers in the first lane between alice + * and bob, and 'y' flowers in the second lane between them. return the number + * of possible pairs '(x, y)' that satisyf the conditions mentioned in the + * statement. + */ + +long long flowerGame(int n, int m) { return 1LL * n * m / 2; } + +int main() { + printf("%lld\n", flowerGame(3, 2)); // expect: 3 + printf("%lld\n", flowerGame(1, 1)); // expect: 0 +} diff --git a/alice_bob_flower_game.py b/alice_bob_flower_game.py new file mode 100644 index 0000000..96e336d --- /dev/null +++ b/alice_bob_flower_game.py @@ -0,0 +1,25 @@ +# 3021. Alice and Bob Playing Flower Game + +""" +alice and bob are playing a turn-based game on a field with two lanes of +flowers bet=een them. there are 'x' flowers in the first lane between alice +and bob, and 'y' flowers in the second lane between them. return the number +of possible pairs '(x, y)' that satisyf the conditions mentioned in the +statement. +""" + + +class Solution(object): + def flowerGame(self, n, m): + """ + :type n: int + :type m: int + :rtype: int + """ + return n * m // 2 + + +if __name__ == "__main__": + obj = Solution() + print(obj.flowerGame(3, 2)) + print(obj.flowerGame(1, 1)) |