非常简单,直接上代码:
int minimalRepresentation() { int n = strlen(str); int i = 0,j = 1, k = 0; while(i<n && j<n && k<n) { int t = str[(i+k)%n] - str[(j+k)%n] ; if(t == 0) k++; else { if(t>0) i+=k+1; else j+=k+1; if(i==j) j++; k = 0; } } return i < j ? i : j; }
原文地址:https://www.cnblogs.com/Alex-leaves/p/8464008.html
时间: 2024-11-05 21:56:27