微信小程序换肤功能实现方法详细步骤与探讨
801
2022-11-09
LeetCode-132. Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome.
Return the minimum cuts needed for a palindrome partitioning of s.
Example:
Input: "aab"Output: 1Explanation: The palindrome partitioning ["aa","b"] could be produced using 1 cut.
题解:
用函数判断效率很低:
class Solution {public: bool isPalindrome (string &s) { int n = s.length(); for (int i = 0; i < n / 2; i++) { if (s[i] != s[n - i - 1]) { return false; } } return true; } int minCut(string &s) { int n = s.length(); vector
即时判断:
class Solution {public: int minCut(string s) { int n = s.length(); vector
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~