<commit_before><commit_msg>Create 078_Palindrome_Partitioning.cpp<commit_after>/*
 * Palindrome Partitioning
 * Total Accepted: 11172 Total Submissions: 43277
 *
 * 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"]
 *   ]
 *
 */
class Solution
{
public:
    vector<vector<string> > partition(string s)
    {
        vector<vector<string> > result;
        if (s.size() == 1)
        {
            result.resize(1);
            result[0].resize(1);
            result[0][0] = s;
        }
        else if (s.size() > 1)
        {
            for (int i = 1; i < s.size(); i++)
            {
                if (valid(s.substr(0, i)))
                {
                    vector<vector<string> > tmp;
                    string sub = s.substr(i, s.size() - i);
                    tmp = partition(sub);

                    if (tmp.size())
                    {
                        int originalSize = result.size();
                        int newSize = originalSize + tmp.size();
                        result.resize(newSize);

                        for (int j = 0; j < tmp.size(); j++)
                        {
                            result[j + originalSize].push_back(s.substr(0, i));

                            for (int k = 0; k < tmp[j].size(); k++)
                            {
                                result[j + originalSize].push_back(tmp[j][k]);
                            }
                        }
                    }
                }
            }

            if (valid(s))
            {
                result.resize(result.size() + 1);
                result[result.size() - 1].push_back(s);
            }
        }
        return result;
    }

    bool valid(string s)
    {
        int i = 0;
        int j = s.size() - 1;
        while (i < j)
        {
            if (s[i] != s[j])
            {
                return false;
            }
            i++;
            j--;
        }
        return true;
    }
};

{'fraction_non_alphanumeric': 0.12993039443155452, 'fraction_numerical': 0.01345707656612529, 'mean_word_length': 0.988929889298893, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '643679', 'n_tokens_mistral': 641, 'n_tokens_neox': 595, 'n_words': 138}