연속되지 않으면서 같은 문자가 나오면 NO
import sys
input = sys.stdin.readline
for test in range(int(input())):
n = int(input())
a = list(input().rstrip())
char_set = {a[0]: True}
for i in range(1, n):
if a[i - 1] != a[i]:
if a[i] in char_set:
print('NO')
break
else:
char_set[a[i]] = True
else:
print('YES')
'practivceAlgorithm > codeforce' 카테고리의 다른 글
[codeforce][Python] #719 C.Not Adjacent Matrix (0) | 2021.10.17 |
---|---|
[codeforce][Python] #719 B.Ordinary Numbers (0) | 2021.10.17 |
[Codefroce][Python] div.3 #731 - E. Air Conditioners (0) | 2021.10.03 |
[Codefroce][Python] div.3 #731 - D. Co-growing Sequence (0) | 2021.10.03 |
[Codefroce][Python] div.3 #731 - C. Pair Programming (0) | 2021.10.03 |