Guest User

Untitled

a guest
May 25th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. class Solution:
  2. def largeGroupPositions(self, S):
  3. """
  4. :type S: str
  5. :rtype: List[List[int]]
  6. """
  7.  
  8. last = None
  9. result = []
  10. start = 0
  11. end = 0
  12.  
  13. for i in range(len(S)):
  14. if S[i] == last:
  15. end = i
  16. else:
  17. if end - start >= 2:
  18. result.append([start, end])
  19.  
  20. last = S[i]
  21. start = i
  22. end = i
  23.  
  24. if end - start >= 2:
  25. result.append([start, end])
  26.  
  27. return result
Add Comment
Please, Sign In to add comment