You have 4 cards each containing a number from 1 to 9. You need to judge whether they could operated through *, /, +, -, (, )to get the value of 24. Example 1: Input: [4, 1, 8, 7] Output: True Explanation: (8-4) * (7-1) = 24 Example 2: Input: [1, 2,…
思路: 数据结构中,栈可以解决运算的问题.利用压栈和弹栈操作实现(这里用队列模拟).具体的: 遇到乘除号,弹出栈顶元素,将计算结果压入栈中.遇到加减号,将后面的数一起压入栈中. 注意: substring方法前闭后开,substring(i, i + 2)取的是i和i+1. 在ASCII码里'0'对应的刚好是48的二进制码,所以用字符串减去'0'即为整数. import java.util.Scanner; public class Main { public static void main(…