Created
March 22, 2014 13:51
-
-
Save davidsan/9707458 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InterestingNumber { | |
// srm 611 div 2 | |
public String isInteresting(String x) { | |
// For each D between 0 and 9, inclusive, X either does not contain the | |
// digit D at all, or it contains exactly two digits D, and there are | |
// precisely D other digits between them. | |
for (int i = 0; i <= 9; i++) { | |
String line = x; | |
int count = line.length() - line.replace(i + "", "").length(); | |
if (count == 0) { | |
continue; | |
} else { | |
if (count != 2) { | |
return "Not Interesting"; | |
} else { | |
line = x; | |
int begin = -1; | |
int j = 0; | |
for (; j < line.length(); j++) { | |
if ((line.charAt(j) + "").compareTo("" + i) == 0) { | |
if (begin < 0) { | |
begin = j; | |
} else { | |
break; | |
} | |
} | |
} | |
if (i != j - begin - 1) { | |
return "Not Interesting"; | |
} | |
} | |
} | |
} | |
return "Interesting"; | |
} | |
public static void main(String[] args) { | |
InterestingNumber in = new InterestingNumber(); | |
System.err.println(in.isInteresting("2002")); | |
System.err.println(in.isInteresting("1001")); | |
System.err.println(in.isInteresting("41312432")); | |
System.err.println(in.isInteresting("611")); | |
System.err.println(in.isInteresting("64200246")); | |
System.err.println(in.isInteresting("631413164")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment