Solved LeetCode program · 919 of 1,000
#1278 · Palindrome Partitioning III
Original English source
The word is "abc". The parts is 2. Keep a shared size of 3. Keep a shared width of size plus 1. Keep a shared costs as an empty list of whole numbers. Keep a shared scores as an empty list of whole numbers.
For every spot from 0 to 8.
Place 0 into costs.
For every spot from 0 to 11.
Place 1000000 into scores.
Set item 0 of scores to 0.
For every start from 0 to size minus 1.
For every finish from start to size minus 1.
The left is start. The right is finish.
Repeat while left is less than right.
If character left of word is not character right of word, Set item (start times size plus finish) of costs to item (start times size plus finish) of costs plus 1. Add 1 to left. Subtract 1 from right.
To measure from cuts (a whole number) with finish (a whole number). The least is 1000000.
For every start from 0 to finish minus 1.
The previous is item ((cuts minus 1) times width plus start) of scores. The change is item (start times size plus finish minus 1) of costs. The candidate is previous plus change. If candidate is less than least, set least to candidate. Set item (cuts times width plus finish) of scores to least.
For every cuts from 1 to parts.
For every finish from 1 to size.
Measure from cuts with finish.
Show item (parts times width plus size) of scores.
Expected stdout
1