Back to course home
0% completed
Vote For New Content
Another O(n^2) method with golang using bit mask
Castor Will
Dec 17, 2024
import ( "unicode" ) // Solution struct for encapsulating the algorithm type Solution struct{} func (s Solution) findLongestNiceSubstring(str string) string { var result string for i := 0; i < len(str); i++ { var lowerBits, upperBits int for j := i; j < len(str); j++ { if unicode.IsLower(rune(str[j])) { lowerBits |= 1 << (str[j] - 'a') } else { upperBits |= 1 << (str[j] - 'A') } if lowerBits == upperBits && j-i+1 > len(result) { result = str[i : j+1] } } } return result }
0
0
Comments
Comments
On this page