-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
577 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
markdowns/_1381. Design a Stack With Increment Operation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# 1381. [Design a Stack With Increment Operation](<https://leetcode.com/problems/design-a-stack-with-increment-operation>) | ||
|
||
*[Back to top](<../README.md>)* | ||
|
||
------ | ||
|
||
> *First completed : July 05, 2024* | ||
> | ||
> *Last updated : July 05, 2024* | ||
|
||
------ | ||
|
||
> **Related Topics** : **[Array](<by_topic/Array.md>), [Stack](<by_topic/Stack.md>), [Design](<by_topic/Design.md>)** | ||
> | ||
> **Acceptance Rate** : **77.091 %** | ||
|
||
------ | ||
|
||
*To see the question prompt, click the title.* | ||
|
||
> ## This question has the honour of being my 400th question on LeetCode. | ||
> | ||
> **On Day 39 of my grind, 8:35PM PST, this question was done. Simple one to end off this sprint. :)** | ||
------ | ||
|
||
## Solutions | ||
|
||
- [m1381.py](<../my-submissions/m1381.py>) | ||
### Python | ||
#### [m1381.py](<../my-submissions/m1381.py>) | ||
```Python | ||
class CustomStack: | ||
|
||
def __init__(self, maxSize: int): | ||
self.stk = [] | ||
self.maxx = maxSize | ||
|
||
def push(self, x: int) -> None: | ||
if len(self.stk) >= self.maxx : | ||
return | ||
self.stk.append(x) | ||
|
||
def pop(self) -> int: | ||
if not self.stk : | ||
return -1 | ||
return self.stk.pop() | ||
|
||
def increment(self, k: int, val: int) -> None: | ||
for i in range(min(k, len(self.stk))) : | ||
self.stk[i] += val | ||
|
||
|
||
# Your CustomStack object will be instantiated and called as such: | ||
# obj = CustomStack(maxSize) | ||
# obj.push(x) | ||
# param_2 = obj.pop() | ||
# obj.increment(k,val) | ||
``` | ||
|
Oops, something went wrong.