10-line Python


  • 0
    Z

    '''
    def solveEquation(self, equation):
    """
    :type equation: str
    :rtype: str
    """
    eq = re.sub(r'(\d+)x',r'\1*x',equation)
    eq1 = eq.replace("=","-(")+")"
    c = eval(eq1,{'x':1j})
    if c.imag==0:
    if c.real==0:
    return "Infinite solutions"
    else:
    return "No solution"
    r=-c.real/c.imag
    return 'x='+str(int(r))
    '''


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.