일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- shiba
- 715. Range Module
- data science
- 프로그래머스
- kaggle
- Convert Sorted List to Binary Search Tree
- 컴퓨터의 구조
- 운영체제
- 43. Multiply Strings
- Python Implementation
- 315. Count of Smaller Numbers After Self
- Class
- 109. Convert Sorted List to Binary Search Tree
- DWG
- 파이썬
- concurrency
- Regular Expression
- Protocol
- Generator
- 30. Substring with Concatenation of All Words
- t1
- iterator
- LeetCode
- 밴픽
- 시바견
- Decorator
- Python
- Substring with Concatenation of All Words
- Python Code
- attribute
Archives
- Today
- Total
Scribbling
[C++] istringstream 본문
LeetCode 290. Word Pattern
https://leetcode.com/problems/word-pattern/
class Solution {
public:
bool wordPattern(string pattern, string s) {
unordered_map<char, string> patternMap;
unordered_set<string> wordSet;
istringstream iss(s);
int i = 0, n = pattern.length();
for (string word; iss >> word; i++) {
if (i == n)
return false;
char p = pattern[i];
if (patternMap.find(p) == patternMap.end()) {
if (wordSet.find(word) == wordSet.end()) {
patternMap[p] = word;
wordSet.insert(word);
}
else {
return false;
}
}
else {
if (word != patternMap[p]) {
return false;
}
}
}
return i == n;
}
};
'Computer Science > C++' 카테고리의 다른 글
[C++] ostringstream, isdigit (0) | 2023.08.29 |
---|---|
[C++] to_string, deque, string split (0) | 2023.08.24 |
[C++] Chapter 2: Types (0) | 2023.08.21 |
[C++] Load Balancing (0) | 2023.08.19 |
[C++] lower_bound, upper_bound (0) | 2023.08.18 |