일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 알고리즘
- MATLAB
- 개발자
- C++
- zeros
- 캐나다 영주권
- 컴퓨터과학과
- omscs
- 머신러닝
- cpp
- machine learning
- 매트랩
- 기본
- 방송통신대학교
- 조지아텍
- 딥러닝
- LAA
- mpnp
- LV1
- Deep learning
- 방통대
- 프로그래머스
- 코딩테스트
- 선형대수
- 주정부이민
- 위니펙
- leetcode
- 온라인석사
- EOI
- Plotting
Archives
- Today
- Total
Byte by Byte
1381. Design a Stack With Increment Operation.cpp 본문
스택 구현 문제. 숙달이 중요한 것 같다.
class CustomStack {
public:
int maxn;
int top;
int *st;
CustomStack(int maxSize) {
maxn = maxSize;
st = new int[maxn];
top = -1;
}
void push(int x) {
if(top != maxn-1){
st[++top] = x;
}
}
int pop() {
if(top==-1) return -1;
return st[top--];
}
void increment(int k, int val) {
int inc = min(k-1,top);
for(int i =0; i<=inc;i++){
st[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);
*/
'개발 로그 > 알고리즘' 카테고리의 다른 글
1557. Minimum Number of Vertices to Reach All Nodes.cpp (0) | 2021.10.07 |
---|---|
1941. Check if All Characters Have Equal Number of Occurrences.cpp (0) | 2021.10.07 |
1812. Determine Color of a Chessboard Square.cpp (0) | 2021.10.07 |
980. Unique Paths III.cpp (0) | 2021.10.07 |
1967. Number of Strings That Appear as Substrings in Word.cpp (0) | 2021.10.06 |