-
Notifications
You must be signed in to change notification settings - Fork 0
/
1169.invalid-transactions.java
54 lines (43 loc) · 2.03 KB
/
1169.invalid-transactions.java
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
class Solution {
boolean vis[];
List<String> res;
public List<String> invalidTransactions(String[] transactions) {
vis = new boolean[transactions.length];
res = new ArrayList<String>();
for(int i=0;i<transactions.length;i++){
String[] currTransaction = transactions[i].split(",");
for(int j=i+1;j<transactions.length;j++){
String[] nextTransaction = transactions[j].split(",");
// solve(transactions, i, transactions[i]);
if(currTransaction[0].equals(nextTransaction[0]) && Math.abs(Integer.parseInt(currTransaction[1])-Integer.parseInt(nextTransaction[1])) <= 60 && !(currTransaction[3].equals(nextTransaction[3])))
{
vis[i] = true;
vis[j]= true;
}
}
if(Integer.parseInt(currTransaction[2]) > 1000 )
// res.add(transactions[i]);
vis[i] = true;
}
for(int i=0;i<transactions.length;i++)
if(vis[i])
res.add(transactions[i]);
return res;
}
public void solve(String[] transactions, int i, String currTrans){
boolean invalid = false;
String[] currTransaction = currTrans.split(",");
for(int j=i+1;j<transactions.length;j++){
String[] nextTransaction = transactions[j].split(",");
if(currTransaction[0].equals(nextTransaction[0]) && Math.abs(Integer.parseInt(currTransaction[1])-Integer.parseInt(nextTransaction[1])) <= 60 && !(currTransaction[3].equals(nextTransaction[3])))
{
vis[j] = true;
solve(transactions, j, transactions[j]);
vis[i] = true;
}
}
if(Integer.parseInt(currTransaction[2]) > 1000 || invalid)
// res.add(transactions[i]);
vis[i] = true;
}
}