일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- machine learning
- 조지아텍
- 캐나다 영주권
- cpp
- 프로그래머스
- 기본
- 머신러닝
- 온라인석사
- C++
- zeros
- omscs
- 컴퓨터과학과
- 딥러닝
- LV1
- 방송통신대학교
- mpnp
- Deep learning
- 매트랩
- 마니토바
- 코딩테스트
- EOI
- 주정부이민
- MATLAB
- Plotting
- 방통대
- 선형대수
- leetcode
- 알고리즘
- LAA
- 개발자
Archives
- Today
- Total
Krononberg
890. Find and Replace Pattern.cpp 본문
map의 해당key에 값이 있는지 확인하려면 m.count("key").
true 1
else 0 리턴
class Solution {
public:
string helper(string s){
map<char,int>m;
string t;
for(int i =0; i<s.size();i++){
if(m.count(s[i])==0) {
m[s[i]] = i;
t += to_string(i);
}
else{
t +=to_string(m[s[i]]);
}
}
return t;
}
vector<string> findAndReplacePattern(vector<string>& words, string pattern) {
vector<string>res;
for(int i =0; i<words.size(); i++){
if(helper(pattern)==helper(words[i])) res.push_back(words[i]);
}
return res;
}
};
'개발 로그 > 알고리즘' 카테고리의 다른 글
1347. Minimum Number of Steps to Make Two Strings Anagram.cpp (0) | 2021.10.08 |
---|---|
897. Increasing Order Search Tree.cpp (0) | 2021.10.08 |
1079. Letter Tile Possibilities.cpp (0) | 2021.10.07 |
950. Reveal Cards In Increasing Order.cpp (0) | 2021.10.07 |
921. Minimum Add to Make Parentheses Valid.cpp (0) | 2021.10.07 |