Open devLupin opened 1 year ago
문제링크
내 풀이
[map을 사용해서 알파벳 배열을 사용하지 않는 기법]
#include <string> #include <vector> #include <map> using namespace std; vector<int> solution(string s) { map<char, int> mp; vector<int> answer; for (int i = 0; i < s.size(); ++i) { if (mp.find(s[i]) != mp.end()) answer.push_back(i - mp[s[i]]); else answer.push_back(-1); mp[s[i]] = i; } return answer; }
문제링크
내 풀이
[map을 사용해서 알파벳 배열을 사용하지 않는 기법]