Class Solution
-
- All Implemented Interfaces:
public final class Solution3707 - Equal Score Substrings.
Easy
You are given a string
sconsisting of lowercase English letters.The score of a string is the sum of the positions of its characters in the alphabet, where
'a' = 1,'b' = 2, ...,'z' = 26.Determine whether there exists an index
isuch that the string can be split into two non-empty substringss[0..i]ands[(i + 1)..(n - 1)]that have equal scores.Return
trueif such a split exists, otherwise returnfalse.A substring is a contiguous non-empty sequence of characters within a string.
Example 1:
Input: s = "adcb"
Output: true
Explanation:
Split at index
i = 1:Left substring =
s[0..1] = "ad"withscore = 1 + 4 = 5Right substring =
s[2..3] = "cb"withscore = 3 + 2 = 5
Both substrings have equal scores, so the output is
true.Example 2:
Input: s = "bace"
Output: false
Explanation:
No split produces equal scores, so the output is
false.Constraints:
2 <= s.length <= 100sconsists of lowercase English letters.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final BooleanscoreBalance(String s)-
-
Method Detail
-
scoreBalance
final Boolean scoreBalance(String s)
-
-
-
-