What's wrong with my Java solution?


  • 0
    M
    	ScriptEngineManager manager = new ScriptEngineManager();
    	ScriptEngine se = manager.getEngineByName("javascript");
    	String result = "";
    	String operate = str.replaceAll("[\\W]","");
    	if(!operate.trim().equals("")){
    		try {
    			result = se.eval(str).toString();
    			return Integer.parseInt(result);
    		} catch (ScriptException e) {
    			e.printStackTrace();
    		}
    	}
    	return 0;

  • 0
    M

    I'm sorry that i did not get the question correctly.It doesn't mean to calculate the input formula.


Log in to reply
 

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