leetcode在力扣 App 中打开
调试中...
调试中...
题目描述
题目描述
题解
题解
提交记录
提交记录
代码
代码
测试用例
测试用例
测试结果
测试结果
中等
相关标签
相关企业
提示

给你一个字符串 s 和一个整数 k 。请你用 s 字符串中 所有字符 构造 k 个非空  。

如果你可以用 s 中所有字符构造 k 个回文字符串,那么请你返回 True ,否则返回 False 。

 

示例 1:

输入:s = "annabelle", k = 2
输出:true
解释:可以用 s 中所有字符构造 2 个回文字符串。
一些可行的构造方案包括:"anna" + "elble","anbna" + "elle","anellena" + "b"

示例 2:

输入:s = "leetcode", k = 3
输出:false
解释:无法用 s 中所有字符构造 3 个回文串。

示例 3:

输入:s = "true", k = 4
输出:true
解释:唯一可行的方案是让 s 中每个字符单独构成一个字符串。

 

提示:

  • 1 <= s.length <= 105
  • s 中所有字符都是小写英文字母。
  • 1 <= k <= 105
通过次数
12K
提交次数
19.4K
通过率
61.9%


相关企业

提示 1
If the s.length < k we cannot construct k strings from s and answer is false.

提示 2
If the number of characters that have odd counts is > k then the minimum number of palindrome strings we can construct is > k and answer is false.

提示 3
Otherwise you can construct exactly k palindrome strings and answer is true (why ?).

评论 (0)

贡献者
© 2025 领扣网络(上海)有限公司
1 人在线
行 1,列 1
s =
"annabelle"
k =
2
Source