We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4f98f47 commit 76ce797Copy full SHA for 76ce797
TypeScript/counter-ii.ts
@@ -0,0 +1,30 @@
1
+// Time: ctor: O(1)
2
+// increment: O(1)
3
+// decrement: O(1)
4
+// reset: O(1)
5
+// Space: O(1)
6
+
7
+// design
8
+class Counter {
9
+ init: number;
10
+ curr: number;
11
+ constructor(init: number) {
12
+ this.curr = this.init = init;
13
+ }
14
15
+ increment() {
16
+ return ++this.curr;
17
18
19
+ decrement() {
20
+ return --this.curr;
21
22
23
+ reset() {
24
+ return this.curr = this.init;
25
26
+};
27
28
+function createCounter(init: number) {
29
+ return new Counter(init);
30
0 commit comments