-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1381-DesignAStackWithIncrementOperation.cs
48 lines (41 loc) · 1.18 KB
/
1381-DesignAStackWithIncrementOperation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//-----------------------------------------------------------------------------
// Runtime: 152ms
// Memory Usage: 38.7 MB
// Link: https://leetcode.com/submissions/detail/360764155/
//-----------------------------------------------------------------------------
using System;
namespace LeetCode
{
public class _1381_DesignAStackWithIncrementOperation
{
private readonly int[] data;
private int size;
public _1381_DesignAStackWithIncrementOperation(int maxSize)
{
data = new int[maxSize];
size = 0;
}
public void Push(int x)
{
if (size == data.Length) return;
data[size++] = x;
}
public int Pop()
{
if (size == 0) return -1;
return data[--size];
}
public void Increment(int k, int val)
{
for (int i = 0; i < Math.Min(k, size); i++)
data[i] += val;
}
}
/**
* Your CustomStack object will be instantiated and called as such:
* CustomStack obj = new CustomStack(maxSize);
* obj.Push(x);
* int param_2 = obj.Pop();
* obj.Increment(k,val);
*/
}