Skip to content

Commit

Permalink
feat(leetcode): add 2665 easy
Browse files Browse the repository at this point in the history
  • Loading branch information
benben6515 committed May 7, 2023
1 parent 8033ef8 commit c7a834e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions leetcode-easy/2620-counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ function createCounter(n: number): () => number {
}
}

export { createCounter }

/**
* const counter = createCounter(10)
* counter() // 10
Expand Down
37 changes: 37 additions & 0 deletions leetcode-easy/2665-counter-II.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
type ReturnObj = {
increment: () => number
decrement: () => number
reset: () => number
}

function createCounter(init: number): ReturnObj {
let currentValue = init

return {
increment() {
currentValue++
return currentValue
},
decrement() {
currentValue--
return currentValue
},
reset() {
currentValue = init
return currentValue
},
}
}

export { createCounter }

/**
* const counter = createCounter(5)
* counter.increment(); // 6
* counter.reset(); // 5
* counter.decrement(); // 4
*/

// 2023/05/07 done
// Runtime 74 ms Beats 56.14%
// Memory 45.4 MB Beats 73.68%

0 comments on commit c7a834e

Please sign in to comment.