Skip to content

Instantly share code, notes, and snippets.

@BiruLyu
Created May 8, 2018 21:24
Show Gist options
  • Save BiruLyu/0cdc9153f623ed6ef7faec8fda156a44 to your computer and use it in GitHub Desktop.
Save BiruLyu/0cdc9153f623ed6ef7faec8fda156a44 to your computer and use it in GitHub Desktop.
class Solution {
public int uniqueLetterString(String S) {
char[] s = S.toCharArray();
int n = s.length;
int mod = 1000000007;
long ret = 0;
for(int i = 0;i < s.length;i++){
int l = i-1;
for(;l >= 0 && s[l] != s[i];l--);
int r = i+1;
for(;r < n && s[r] != s[i];r++);
ret += (long)(r-i)*(i-l);
}
return (int)(ret%mod);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment