-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathColorfulNumber.java
More file actions
40 lines (32 loc) · 786 Bytes
/
ColorfulNumber.java
File metadata and controls
40 lines (32 loc) · 786 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
package Hashing;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/**
* Author - archit.s
* Date - 28/10/18
* Time - 2:01 PM
*/
public class ColorfulNumber {
public int colorful(int A) {
Map<Long, Boolean> map = new HashMap<>();
ArrayList<Long> r = new ArrayList<>();
while(A>0){
r.add(0, (long) (A%10));
A/=10;
}
for(int i=0;i<r.size();i++){
long product = 1;
for(int j=i;j<r.size();j++){
product *= r.get(j);
if(!map.containsKey(product)){
map.put(product,true);
}
else{
return 0;
}
}
}
return 1;
}
}