討論串[閒聊] 每日leetcode
共 1553 篇文章
內容預覽:
思路:. 先統計各個字母個數. 有兩種狀況無法達成題目要求:. 1. 字母個數為奇數的數量 > k. 2. s長度 < k. 其他都能達成題目要求. python:. class Solution:. def canConstruct(self, s: str, k: int) -> bool:.
(還有340個字)
內容預覽:
1400. Construct K Palindrome Strings. ## 思路. 1.字串長度必須要大於K. 2.回文: AABB / ABA. 計算字元的奇偶個數 最多只能有K個字元是奇數個. ## CODE. ```CPP. class Solution {. public:. bool
(還有212個字)
內容預覽:
題目. 這字串能不能弄成K個回文字串. 思路. 一定要偶數才能弄到回文的兩邊. 奇數只能放中間 所以不能超過k個. class Solution {. public:. bool canConstruct(string s, int k). {. int n = s.size();. if(k ==
(還有271個字)
內容預覽:
差不多硬幹. 在下今天原本想學KMP的. 但老天爺不給我機會. 一輩子學不會KMP. def wordSubsets(self, words1: List[str], words2: List[str]) -> List[str]:. def check(a_cnt,b_cnt):. for i i
(還有512個字)
內容預覽:
題目. 找words1 裡面有幾個字串是好的. 好的 = 出現的字母比words2 每一個string裡面出現的字母還要多. 思路. 先找words2每個字母出現最多次的次數. 這一定是word1 分別字母 至少要出現的次數. 就好了. class Solution {. public:. vect
(還有866個字)