일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 온라인석사
- 알고리즘
- EOI
- C++
- LAA
- cpp
- 매트랩
- Plotting
- 코딩테스트
- 선형대수
- 방통대
- 캐나다 영주권
- 딥러닝
- 주정부이민
- omscs
- 방송통신대학교
- 컴퓨터과학과
- MATLAB
- Deep learning
- 기본
- machine learning
- LV1
- 머신러닝
- zeros
- 프로그래머스
- 조지아텍
- mpnp
- 위니펙
- leetcode
- 개발자
Archives
- Today
- Total
Byte by Byte
1742. Maximum Number of Balls in a Box.cpp 본문
처음으로 map을 자연스럽게 써보았다.
🔑 주어진 번호를 쪼개서, key값을 만든다음, 그 key의 value를 1씩 늘려준다.
그리고 map에서 최대값을 찾는다.
class Solution {
public:
int countBalls(int lowLimit, int highLimit) {
map<int,int>m;
for(int i=lowLimit; i<=highLimit;i++){
string tmp = to_string(i);
int sum =0;
for(int j =0; j<tmp.size(); j++){
sum+= tmp[j]-'0';
}
m[sum]++;
}
int max=-1;
for(auto &it : m){
if(it.second > max){
max = it.second;
}
}
return max;
}
};
'개발 로그 > 알고리즘' 카테고리의 다른 글
811. Subdomain Visit Count.cpp (0) | 2021.10.20 |
---|---|
1448. Count Good Nodes in Binary Tree.cpp (0) | 2021.10.19 |
2042. Check if Numbers Are Ascending in a Sentence.cpp (0) | 2021.10.18 |
1850. Minimum Adjacent Swaps to Reach the Kth Smallest Number.cpp (0) | 2021.10.17 |
1472. Design Browser History.cpp (0) | 2021.10.15 |