From 963db26f9b871a805d45b889aa6dfbd2a53ad925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Antonio=20Chac=C3=B3n=20Guti=C3=A9rrez?= <138903866+joseantoniochacon@users.noreply.github.com> Date: Tue, 18 Jun 2024 20:48:55 -0600 Subject: [PATCH] Create README - LeetHub --- 2665-counter-ii/README.md | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 2665-counter-ii/README.md diff --git a/2665-counter-ii/README.md b/2665-counter-ii/README.md new file mode 100644 index 0000000..5b95de7 --- /dev/null +++ b/2665-counter-ii/README.md @@ -0,0 +1,44 @@ +
Write a function createCounter
. It should accept an initial integer init
. It should return an object with three functions.
The three functions are:
+ +increment()
increases the current value by 1 and then returns it.decrement()
reduces the current value by 1 and then returns it.reset()
sets the current value to init
and then returns it.+
Example 1:
+ +Input: init = 5, calls = ["increment","reset","decrement"] +Output: [6,5,4] +Explanation: +const counter = createCounter(5); +counter.increment(); // 6 +counter.reset(); // 5 +counter.decrement(); // 4 ++ +
Example 2:
+ +Input: init = 0, calls = ["increment","increment","decrement","reset","reset"] +Output: [1,2,1,0,0] +Explanation: +const counter = createCounter(0); +counter.increment(); // 1 +counter.increment(); // 2 +counter.decrement(); // 1 +counter.reset(); // 0 +counter.reset(); // 0 ++ +
+
Constraints:
+ +-1000 <= init <= 1000
0 <= calls.length <= 1000
calls[i]
is one of "increment", "decrement" and "reset"