일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 알고리즘
- LV1
- 코딩테스트
- 기본
- 온라인석사
- 방통대
- 개발자
- 방송통신대학교
- 선형대수
- 조지아텍
- LAA
- 머신러닝
- zeros
- leetcode
- mpnp
- cpp
- machine learning
- EOI
- MATLAB
- 캐나다 영주권
- 딥러닝
- omscs
- 주정부이민
- 위니펙
- 매트랩
- 프로그래머스
- 컴퓨터과학과
- Plotting
- C++
- Deep learning
Archives
- Today
- Total
Byte by Byte
leetcode) 1769. Minimum Number of Operations to Move All Balls to Each Box / C++ 본문
개발 로그/알고리즘
leetcode) 1769. Minimum Number of Operations to Move All Balls to Each Box / C++
CyberSoak 2021. 9. 18. 16:31
class Solution {
public:
vector<int> minOperations(string boxes) {
int n = boxes.size();
vector<int> res(n);
unordered_set<int> st;
for (int i = 0; i < n; ++i) {
if (boxes[i] == '1') st.insert(i);
}
for (int i = 0; i < n; ++i) {
for (auto idx : st) {
res[i] += abs(idx - i);
}
}
return res;
}
};
'개발 로그 > 알고리즘' 카테고리의 다른 글
leetcode) 1282. Group the People Given the Group Size They Belong To c++ (0) | 2021.09.21 |
---|---|
leetcode) 807. Max Increase to Keep City Skyline c++ (0) | 2021.09.20 |
Leetcode) 1816. Truncate Sentence c++ (0) | 2021.09.14 |
프로그래머스) 최댓값과 최솟값 c++ (0) | 2021.09.13 |
프로그래머스) 문자열 내 마음대로 정렬하기 c++ (0) | 2021.09.04 |