《leetcode 详解 24 点游戏》由会员分享,可在线阅读,更多相关《leetcode 详解 24 点游戏(2页珍藏版)》请在金锄头文库上搜索。
1、679. 24 点玩耍EnglishVersion题目描述你有4 张写有1 到9 数字的牌。你需要推断是否能通过* ,/,+,-,(,) 的运算得到24 。例如1:输入:4,1,8,7输出:True 解释:(8-4)*(7-1)=24例如2:输入:1,2,1,2输出:False 留意:除法运算符/ 表示实数除法,而不是整数除法。例如4/(1-2/3)=12。每个运算符对两个数进展运算。特别是我们不能用- 作为一元运算符。例如,1,1, 1,1 作为输入时,表达式-1-1-1-1是不允许的。你不能将数字连接在一起。例如,输入为1,2,1,2时,不能写成12+12。解法Python3 Java67
2、9. 24 Game中文文档DescriptionYouhave4cardseachcontaininganumberfrom1to9.Youneedtojudgewhether theycouldoperatedthrough*,/,+,-,(,)togetthevalueof24.Example1:Input:4,1,8,7Output:TrueExplanation:(8-4)*(7-1)=24 Example2:Input:1,2,1,2Output:False Note:Thedivisionoperator/representsrealdivision,notintegerdivision.Forexample,4/(1-2/3)=12.Everyoperationdoneisbetweentwonumbers.Inparticular,wecannotuse-asa unaryoperator.Forexample,with1,1,1,1asinput,theexpression-1-1-1-1is notallowed.Youcannotconcatenatenumberstogether.Forexample,iftheinputis1,2,1,2,we cannotwritethisas12+12.SolutionsPython3 Java