일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 머신러닝
- C++
- 조지아텍
- 주정부이민
- omscs
- 선형대수
- MATLAB
- machine learning
- cpp
- zeros
- 마니토바
- LAA
- 컴퓨터과학과
- 온라인석사
- 코딩테스트
- EOI
- 매트랩
- LV1
- 알고리즘
- 개발자
- leetcode
- 방통대
- mpnp
- Plotting
- Deep learning
- 프로그래머스
- 방송통신대학교
- 캐나다 영주권
- 딥러닝
- 기본
Archives
- Today
- Total
Krononberg
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 |