Register
|
Login
Home
News
Competitions
Practice
How to
Rankings
Calendar
Arena
CodeFu 2007
CodeFu'07 Highlights
Jazoon'07 Highlights
Schedule
Rules
Prizes
Results
Competitions
»
Main CodeFu Competitons
»
CodeFu 2007
»
Results
CodeFu 2007 Results
CodeFu Final Round Results
TosheX's solution for 200: Consecutive Numbers, written in Java
public class ConsecutiveNumbers { public boolean isInArray(int[] a, int j){ int n = a.length; for (int i=0; i<n; i++){ if (a[i]==j) return true; } return false; } public int jokers(int[] a){ int n = a.length; int count=0; for (int i=0; i<n; i++){ if (a[i]==0) count++; } return count; } public int longest(int[] a, int j){ int n = a.length; int count=1; int next=a[j]+1; int jokers=jokers(a); boolean thereIsHope=true; for (int i=0; thereIsHope && i<n; i++){ if (isInArray(a, next)) { count++; next++; } else if (jokers>0){ count++; next++; jokers--; } else thereIsHope=false; } return count; } public int longestSequence(int[] numbers) { int n = numbers.length; int longest=0; for (int i=0; i<n; i++) if (longest(numbers, i)>longest) longest=longest(numbers, i); return longest; } }