Triple Doublehtml
import java.util.regex.*; public class TripleAndDouble{ public static int TripleDouble(long num1, long num2){ String str1 = String.valueOf(num1); String regex = "\\d*([0-9])(\\1){2}\\d*"; if(!str1.matches(regex)){ return 0; } Pattern p = Pattern.compile(regex); Matcher m = p.matcher(str1); while(m.find()){ String d = m.group(1); String str2 = String.valueOf(num2); if(str2.contains(d + d)){ return 1; } } return 0; } }
import org.junit.Test; import org.junit.Assert.assertEquals; public class TripleDoubleTest{ @Test public void test1(){ assertEquals(1, TripleAndDouble(451999277L, 41177722899L)); } @Test public void test2(){ assertEquals(0, TripleAndDouble(1222345L, 12345L)); } @Test public void test3(){ assertEquals(0, TripleAndDouble(12345L, 12345L)); } @Test public void test4(){ assertEquals(1, TripleAndDoubl666789L, 12345667L)); } }