LintCode: Calculate Maximum Value II

Calculate Maximum Value II



Given a string of numbers, write a function to find the maximum value from the string, you can add a + or * sign between any two numbers,It’s different with Calculate Maximum Value, You can insert parentheses anywhere.

Example

Given str = 01231, return 12
(0 + 1 + 2) * (3 + 1) = 12 we get the maximum value 12
Given str = 891, return 80
As 8 * (9 + 1) = 80, so 80 is maximum.

Github: code.dennyzhang.com

Credits To: LintCode.com

Leave me comments, if you have better ways to solve.


## Blog link: https://code.dennyzhang.com/calculate-maximum-value-ii
class Solution:
    """
    @param str: a string of numbers
    @return: the maximum value
    """
    def maxValue(self, str):
linkedin
github
slack

Share It, If You Like It.

Leave a Reply

Your email address will not be published.