Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to design priority for operational expressions in big data

2025-01-18 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 big data", which is easy to understand and well-organized. I hope it can help you solve your doubts. Now let the editor lead you to study and learn "how to design priorities for operational expressions in big data".

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: output: explanation: (2-1)-1) = 0 (2-(1-1)) = 2

Example 2:

Input: "2: 3-4: 5" output: [- 34,-14,-10,-10] explain: (2 * (3-(4-5) =-34

Answer:

1public List diffWaysToCompute (String input) {

2 List res = new ArrayList ()

3 for (int I = 0; I < input.length (); iTunes +) {

4 char c = input.charAt (I)

5 if (c = ='-'| | c = ='+'| | c = ='*') {

6 String a = input.substring (0, I)

7 String b = input.substring (I + 1)

8 List al = diffWaysToCompute (a)

9 List bl = diffWaysToCompute (b)

10 for (int x: al) {

11 for (int y: bl) {

12 if (c = ='-') {

13 res.add (x-y)

14} else if (c ='+') {

15 res.add (x + y)

16} else if (c ='*') {

17 res.add (x * y)

18}

19}

20}

21}

22}

23 if (res.size () = = 0)

24 res.add (Integer.valueOf (input))

25 return res

26}

Parsing:

First, the string is intercepted, and then the calculated value is added, subtracted and multiplied by recursion. Notice lines 23 through 24. When truncating the head and tail numbers respectively, res may be empty, so you need to add the input value to the res collection.

The above is all the contents of the article "how to design priorities for operational expressions in big data". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report