Python C++速解Leetcode迴文1400 Construct K Palindrome Strings
關鍵:偶數長度的回文字串中所有字母都出現偶數,奇數長度的回文字串中除了一個例外其他所有字母都出現偶數。
----------
The key observation: palindrome strings of even lengths have all letters even occurrences, palindrome strings of odd lengths have all letters even occurrences but except one letter with odd occurrence.
[Py3解答請進]
[codes on Leetcode]https://leetcode.com/problems/construct-k-palindrome-strings/solutions/6262071/only-consider-the-parity-of-freq-bitset-beats-100/
[C++ python使用DFS與奇偶測試解Leetcode1457 Pseudo Palindromic Paths in a Binary Tree]https://www.youtube.com/watch?v=StHXyYgavUU
[C, C++ ,python速解迴文Leetcode 2108 Find First Palindromic String in the Array]https://www.youtube.com/watch?v=eXhdv8jDpao
class Solution: def canConstruct(self, s: str, k: int) -> bool: n=len(s) if n<k: return False freq=[False]*26 for c in s: freq[ord(c)-97]^=1 return freq.count(True)<=k
沒有留言:
張貼留言