접미사 배열

Subin·2024년 7월 30일

Algorithm

목록 보기
12/69
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

vector<string> solution(string my_string) {
    vector<string> answer;
    int i = 0;
    int l = my_string.length();
    
    while(l--)
    {
        answer.push_back(my_string.substr(i));
        i++;
    }
    sort(answer.begin(), answer.end());
    
    return answer;
}

sort()함수로 오름차순 정렬이 가능하다.

이 때, vector의 처음과 끝을 가져올 땐 인덱스로 가져오는 게 아니라
begin(), end()로 사용하기

profile
성장하며 꿈꾸는 삶을 살아가고 있는 대학생입니다😊

0개의 댓글