AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Leetcode permutation9/14/2023 In each iteration, we append the current character to the window list. Then, we can use a for loop to iterate over the characters in s2. This list will store the characters in the current window that we are checking. We can start by initializing a variable window to an empty list. Now let’s implement the solution in Python.įirst, we need to define the function check_permutation(s1: str, s2: str) -> bool that takes in two strings s1 and s2 and returns a boolean indicating if s2 is a permutation of s1. If we have checked all the windows and none of them is a permutation of s1, we return False. Otherwise, we slide the window by one character to the right and repeat the process until we reach the end of s2. We can slide a window of length len(s1) over the string s2 and check if the characters in the window are a permutation of s1. One approach to solve this problem is to use sliding window technique. The length of s1 and s2 must not exceed 10^4.
0 Comments
Read More
Leave a Reply. |