euisblue
12919. 서울에서 김서방 찾기

Level 1 서울에서 김서방 찾기

시간 복잡도: O(n)

1#include <bits/stdc++.h> 2using namespace std; 3 4string solution(vector<string> seoul) { 5 int i = find(seoul.begin(), seoul.end(), "Kim") - seoul.begin(); 6 string s = "김서방은 " + to_string(i) + "에 있다"; 7 return s; 8}

find()를 사용해서 찾은 위치에서 시작점인 .begin()을 빼주면 위치(인덱스)값을 알 수 있다.

1int index = find(seoul.begin(), seoul.end(), "Kim") - seoul.begin();