File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -474,6 +474,7 @@ Solutions to LeetCode problems. The first column links to the problem in LeetCod
474
474
| [ 2244. Minimum Rounds to Complete All Tasks] [ lc2244 ] | 🟠 Medium | [ ![ python] ( res/py.png )] [ lc2244py ] |
475
475
| [ 2246. Longest Path With Different Adjacent Characters] [ lc2246 ] | 🔴 Hard | [ ![ python] ( res/py.png )] [ lc2246py ] |
476
476
| [ 2256. Minimum Average Difference] [ lc2256 ] | 🟠 Medium | [ ![ python] ( res/py.png )] [ lc2256py ] |
477
+ | [ 2665. Counter II] [ lc2265 ] | 🟢 Easy | [ ![ python] ( res/py.png )] [ lc2265py ] |
477
478
| [ 2279. Maximum Bags With Full Capacity of Rocks] [ lc2279 ] | 🟠 Medium | [ ![ python] ( res/py.png )] [ lc2279py ] |
478
479
| [ 2300. Successful Pairs of Spells and Potions] [ lc2300 ] | 🟠 Medium | [ ![ python] ( res/py.png )] [ lc2300py ] [ ![ rust] ( res/rs.png )] [ lc2300rs ] |
479
480
| [ 2306. Naming a Company] [ lc2306 ] | 🔴 Hard | [ ![ python] ( res/py.png )] [ lc2306py ] [ ![ rust] ( res/rs.png )] [ lc2306rs ] |
@@ -1510,6 +1511,8 @@ Solutions to LeetCode problems. The first column links to the problem in LeetCod
1510
1511
[ lc2246py ] : leetcode/longest-path-with-different-adjacent-characters.py
1511
1512
[ lc2256 ] : https://leetcode.com/problems/minimum-average-difference/
1512
1513
[ lc2256py ] : leetcode/minimum-average-difference.py
1514
+ [ lc2265 ] : https://leetcode.com/problems/counter-ii/
1515
+ [ lc2265py ] : leetcode/counter-ii.js
1513
1516
[ lc2279 ] : https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/
1514
1517
[ lc2279py ] : leetcode/maximum-bags-with-full-capacity-of-rocks.py
1515
1518
[ lc2300 ] : https://leetcode.com/problems/successful-pairs-of-spells-and-potions/
Original file line number Diff line number Diff line change
1
+ // 2665. Counter II
2
+ // 🟢 Easy
3
+ //
4
+ // https://leetcode.com/problems/counter-ii/
5
+ //
6
+ // Tags: Javascript
7
+
8
+ // Use the parameter as state inside the closure and add another variable
9
+ // initialized with the same value, return an object with the three functions
10
+ // that the problem asks for.
11
+ //
12
+ // Time complexity: O(1)
13
+ // Space complexity: O(1)
14
+ //
15
+ // Runtime 69 ms Beats 46.34%
16
+ // Memory 44.9 MB Beats 40.38%
17
+ /**
18
+ * @param {integer } init
19
+ * @return { increment: Function, decrement: Function, reset: Function }
20
+ */
21
+ var createCounter = function ( init ) {
22
+ let n = init ;
23
+ return {
24
+ increment : ( ) => ++ n ,
25
+ decrement : ( ) => -- n ,
26
+ reset : ( ) => ( n = init ) ,
27
+ } ;
28
+ } ;
29
+
30
+ /**
31
+ * const counter = createCounter(5)
32
+ * counter.increment(); // 6
33
+ * counter.reset(); // 5
34
+ * counter.decrement(); // 4
35
+ */
You can’t perform that action at this time.
0 commit comments