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

Sign up
Appearance settings

Commit fc02950

Browse files
ItemAssociation
1 parent 389c799 commit fc02950

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

‎src/leetcode2018/ItemAssociation.java

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class ItemAssociation {
88
public static void main(String[] args) {
99
// TODO Auto-generated method stub
1010
ItemAssociation test = new ItemAssociation();
11-
String[][] mat= new String[][]{{"Item1","Item2"},
11+
String[][] mat= new String[][]{{"Item1","Item2"},
1212
{"Item3","Item4"},
1313
{"Item4","Item5"}};
1414

@@ -17,33 +17,34 @@ public static void main(String[] args) {
1717
}
1818

1919
public String[] largestItemAssociation(String[][] itemAssociation)
20-
{ StringBuffer temp= new StringBuffer();
21-
int n=Integer.MIN_VALUE;
22-
Queue<String> q = new LinkedList<>();
23-
for(int i = 0; i< itemAssociation.length; i++){
24-
if(!q.isEmpty() && q.peek()!=itemAssociation[i][0]){
25-
if(n<q.size()){
26-
n=q.size();
27-
temp.setLength(0);
28-
while(!q.isEmpty()){
29-
temp.append(q.poll()+",");
30-
}
31-
}
20+
{
21+
StringBuffer temp= new StringBuffer();
22+
int n=Integer.MIN_VALUE;
23+
Queue<String> q = new LinkedList<>();
24+
for(int i = 0; i< itemAssociation.length; i++){
25+
if(!q.isEmpty() && q.peek()!=itemAssociation[i][0]){
26+
if(n<q.size()){
27+
n=q.size();
28+
temp.setLength(0);
29+
while(!q.isEmpty()){
30+
temp.append(q.poll()+",");
3231
}
33-
for(int j=0;j< itemAssociation[0].length;j++){
34-
if(!q.contains(itemAssociation[i][j]))
35-
q.offer(itemAssociation[i][j]);
36-
}
37-
}
38-
if(n<q.size()){
39-
n=q.size();
40-
temp.setLength(0);
41-
while(!q.isEmpty()){
42-
temp.append(q.poll()+",");
43-
}
44-
}
45-
String[] re= temp.toString().split(",");
46-
return re;
32+
}
33+
}
34+
for(int j=0;j< itemAssociation[0].length;j++){
35+
if(!q.contains(itemAssociation[i][j]))
36+
q.offer(itemAssociation[i][j]);
37+
}
38+
}
39+
if(n<q.size()){
40+
n=q.size();
41+
temp.setLength(0);
42+
while(!q.isEmpty()){
43+
temp.append(q.poll()+",");
44+
}
45+
}
46+
String[] re= temp.toString().split(",");
47+
return re;
4748
}
4849

4950
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /