In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to design priorities for operational expressions in leetcode", which is easy to understand and well-organized. I hope it can help you solve your doubts. Let me lead you to study and learn "how to design priorities for operational expressions in leetcode".
Given a string containing numbers and operators, add parentheses to the expression and change its priority to get different results. You need to give the results of all possible combinations. Valid operation symbols include +, -, and *.
Example 1:
Input: "2-1-1" output: [0,2] explanation: ((2-1)-1) = 0 (2-(1-1)) = 2 example 2:
Input: "2x 3-4 x 5" output: [- 34,-14,-10,-10, 10] explain: (2 * (3-(4-5) =-34 ((2-3)-(4-5)) =-14 ((2 * (3-4)) * 5) =-10 ((2 * (3-4) * 5) =-10 (2) 3)-4) * 5) = 10
Ideas for solving the problem:
1, split the input string into token
2, split the array into two parts at any operator location
3. Recursively evaluate the two parts
4, operate on the value
Func diffWaysToCompute (input string) [] int {t:=strToTok (input) fmt.Println (t) return cal (t)}
Func cal (t [] Token) [] int {var r [] int if len (t) = = 1 {r=append (r int if len t [0] .value) return r} for ipurl
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.