3340. Check Balanced String
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 81% Topics: String
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
# string
class Solution(object):
def isBalanced(self, num):
"""
:type num: str
:rtype: bool
"""
return sum(ord(num[i])-ord('0') for i in xrange(0, len(num), 2)) == sum(ord(num[i])-ord('0') for i in xrange(1, len(num), 2))
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions