C++ unique 함수를 쓸 때는 꼭 sort를 해줄 것! unique의 complexity는 O(n) #include sort(v.begin(), v.end()); vector::iterator end_iter = unique(v.begin(), v.end()); + 추가: erase 하기 v.erase(unique(v.begin(),v.end()),v.end()) + 추가: 원소 개수 구하기 cout << "#" << test_case << " " << end_iter - v.begin() << endl; Python python의 경우, 쉽게 set을 이용!
list_a = ['a','b','c','a'] print(set(list_a)) 예시 문제: swexpert - 2819. 격자판의 숫자 이어 붙이기 https://github.com/nh9k/algorithm-problem/blob/master/c%2B%2B/2021_swexpert...
#
sort_cpp
#
unique_cpp
#
unique_python
원문 링크 : unique - C++, Python