class Solution { int minOperation (String s) { + s. charAt (0) ; String curr int n = s. length( ) ; boolean flag = false; int prevRep = 0; int count = 1; for (int i = 1; i < n; it+) { if (s. charAt(i) != curr . charAt(0) ) { curr += s. charAt(i) ; } else { if (s. contains (curr + curr) ) { if ( !flag) { prevRep = curr. length( ) ; flag = true; } else { count += prevRep prevRep = curr . length( ) ; += curr . length( ) - 1; curr += curr; } else { curr += s. charAt(i) ; count + + ; return count;

`class Solution: def minOperation(self, s: str) -> int: s = s[0] curr = s[0] n = len(s) flag = False prevRep = 0 count = 1 for i in range(1, n): if s[i] != curr[0]: curr += s[i] else: if curr + curr in s: if not flag: prevRep = len(curr) flag = True else: count += prevRep prevRep = len(curr) count += len(curr) - 1 curr += curr else: curr += s[i] count += 1 return count`