-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlongComPre14.java
More file actions
48 lines (40 loc) · 940 Bytes
/
longComPre14.java
File metadata and controls
48 lines (40 loc) · 940 Bytes
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
package leetCode;
import java.util.Collection;
import java.util.Collections;
public class longComPre14 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] strs= {"flower","flow","flight"};
System.out.println(strs.length);
int count=0;
String ss="";
StringBuilder s =new StringBuilder("");
for (int i=0;i<strs.length-1;i++) {
if (strs[i].length()<=strs[i+1].length())
{
ss=strs[i];
}
else
{
ss=strs[i+1];
}
}
for (int i=0;i<ss.length();i++)
{
char c=ss.charAt(i);
for (int j=0;j<strs.length;j++)
{
if (strs[j].charAt(i)==c)
{
count++;
}
if (count==strs.length)
{
s.append(c);
}
}
count=0;
}
System.out.println(s);
}
}