Skip to content

Instantly share code, notes, and snippets.

@anil477
Created September 29, 2017 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anil477/b05a6961365f79ab41e0e32bf0fe9783 to your computer and use it in GitHub Desktop.
Save anil477/b05a6961365f79ab41e0e32bf0fe9783 to your computer and use it in GitHub Desktop.
public class Solution {
public int colorful(int a) {
String input = String.valueOf(a);
int N = input.length();
HashSet<Long> productOf = new HashSet<>();
List<String> results = new ArrayList<>();
for (int m = 1; m <= N; m++) {
for (int i = 0; i + m <= N; i++) {
results.add(input.substring(i, i + m));
}
}
for (String str : results) {
long product = 1;
for (int i = 0; i < str.length(); i++) {
product = product * Long.valueOf(str.substring(i, i + 1));
}
if (productOf.contains(product))
return 0;
productOf.add(product);
}
return 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment