phatboislym

Untitled

Feb 8th, 2024 (edited)
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | Source Code | 0 0
  1. class Solution:
  2.     def maxLengthBetweenEqualCharacters(self, s: str) -> int:
  3.         if len(s) == len(set(s)):
  4.             return -1
  5.  
  6.         indices: dict = {}
  7.        
  8.         for index, char in enumerate(s):
  9.             if char in indices:
  10.                 indices[char].append(index)
  11.             else:
  12.                 indices[char] = [index]
  13.  
  14.         peak: int = 0
  15.         for key, value in indices.items():
  16.             span: int = max(value) - min(value) - 1
  17.             peak = max(peak, span)
  18.        
  19.         return peak
Advertisement
Add Comment
Please, Sign In to add comment