Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
58 lines (49 loc) · 1.4 KB

File metadata and controls

58 lines (49 loc) · 1.4 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package org.doit;
import java.util.ArrayList;
import java.util.List;
public class test1843 {
public static void main(String[] args) {
String[] arr = {"5", "-", "3", "+", "1", "+", "2", "-", "4" };
String[] arr2 = {"5", "-", "6","-","4","-","5"};
solution(arr2);
}
public static int solution(String arr[]) {
int answer = 0;
List<Integer> minus = new ArrayList<>();
List<Integer> pluse = new ArrayList<>();
String str = "";
for(int i=0; i<arr.length; i++) {
str += arr[i];
}
String[] part = str.split("\\-");
for(int i=part.length-1; i>0; i--) {
System.out.println("**"+part[i]+" i="+i);
int part1 = make_int(part[i]);
int part2 = make_int(part[i-1]);
if(i == 2) {
System.out.println("part2="+part2+" part1="+part1);
if (part2 > part1 )
part[i-1] = (part2-part1) + "";
}
else if(i==1) {
part[i-1] = (part2-part1) + "";
}
else
part[i-1] = (part1+part2) + "";
System.out.println(part1+" "+part2+" / part[i-1]="+part[i-1]);
//part[i-1] = part1-part2+"";
}
System.out.println(part[0]);
answer = Integer.parseInt(part[0]);
return answer;
}
private static int make_int(String str) {
String[] part = str.split("\\+");
int sum = 0;
for(int i=0; i<part.length; i++) {
System.out.println("->"+part[i]);
sum += Integer.parseInt(part[i]);
}
return sum;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.