Created
May 8, 2018 21:24
-
-
Save BiruLyu/0cdc9153f623ed6ef7faec8fda156a44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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