Created
April 29, 2022 11:13
-
-
Save erikseulean/ca1726c4734c268c0adc19de6e58e019 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from functools import lru_cache | |
| def minCut(s: str) -> int: | |
| def is_palindrome(start, end): | |
| while start < end: | |
| if s[start] != s[end]: | |
| return False | |
| start += 1 | |
| end += -1 | |
| return True | |
| def min_cuts | |
| sols = dict() | |
| for i in range(0, len(s)): | |
| for j in range(i + 1): | |
| if not is_palindrome(j, i): | |
| continue | |
| if j - 1 < 0: | |
| sols[i] = 0 | |
| continue | |
| sols[i] = min(sols[i], 1 + sols[j - 1]) if in in sols else 1 + sols[j - 1] | |
| return sols[len(s) - 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment