和大神们学习每天一题(leetcode)-Palindrome Partitioning

Given a string s, partition s such that every substring of the partition is a palindrome.

Return all possible palindrome partitioning of s.

For example, given s = "aab",
Return

[
    ["aa","b"],
    ["a","a","b"]
  ]
功能测试用例:"aab";"aabbaacdc"

特殊测试用例:"a","aa","aaa"

class Solution 
{
public:
	vector> partition(string s) 
	{
		vector> vvstrResult;
		if (s.length() == 0)
			return vvstrResult;
		vector> vvstrTemp;
		long lBegin, lEnd;
		for (unsigned long ulTemp = 0; ulTemp < s.length(); ulTemp++)
		{
			lBegin = 0;
			lEnd = ulTemp;
			while (lBegin <= lEnd)
			{
				if (s[lBegin] != s[lEnd])
					break;
				lBegin++;
				lEnd--;
			}
			if (lBegin > lEnd)
			{
				string strPalin(s, 0, ulTemp + 1);
				string strRemain(s, ulTemp + 1, s.length() - ulTemp - 1);
				vvstrTemp = partition(strRemain);
				if (vvstrTemp.size() == 0)
				{
					vector vstrMiddle(1,strPalin);
					vvstrResult.push_back(vstrMiddle);
				}
				else
				{
					for (unsigned long ulIndex = 0; ulIndex < vvstrTemp.size(); ulIndex++)
					{
						vector::iterator ItePos = vvstrTemp[ulIndex].begin();
						vvstrTemp[ulIndex].insert(ItePos, strPalin);
						vvstrResult.push_back(vvstrTemp[ulIndex]);
					}
				}
			}
		}
		return vvstrResult;
	}
};



你可能感兴趣的:(Leetcode,leetcode,windows,编程)