1classSolution {2func findAnagrams(_ s: String, _ p: String) ->[Int] {3ifs.isEmpty {4return[]5}6varhash = Array(repeating:0, count:256)7forletterinp {8hash[letter.ascii] +=19}10let s = [Character](s), p =[Character](p)11varleft =0, right =0, count =p.count12varresult...
Given an arrayAof strings made only from lowercase letters, return a list of all characters that show up in all strings within the list (including duplicates). For example, if a character occurs 3 times in all strings but not 4 times, you need to include that character three times in the...
0387-First-Unique-Character-in-a-String 0388-Longest-Absolute-File-Path 0389-Find-the-Difference 0390-Elimination-Game 0391-Perfect-Rectangle 0392-Is-Subsequence 0393-UTF-8-Validation 0394-Decode-String 0398-Random-Pick-Index 0401-Binary-Watch 0404-Sum-of-Left-Leaves 0412...
1classSolution {2func rootArray(ofstring:String) ->[Int] {3varrootDic : [UInt32:Int] =[:]4varrootArray : [Int] =[]56varidx : Int =07forpinstring.unicodeScalars {8iflet pRoot =rootDic[p.value] {9rootArray.append(pRoot)10}else{11rootArray.append(idx)12rootDic[p.value] =idx...
Given a stringS, return the number of substrings of lengthKwith no repeated characters. Example 1: Input: S ="havefunonleetcode", K =5 Output:6 Explanation: There are 6 substrings they are : 'havef','avefu','vefun','efuno','etcod','tcode'. ...
A string isgoodif it can be formed by characters fromchars(each character can only be used once). Return the sum of lengths of all good strings inwords. Example 1: Input: words =["cat","bt","hat","tree"], chars ="atach"