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
sqrt_x's solution for 200: Consecutive Numbers, written in Java
public class ConsecutiveNumbers { public int longestSequence(int[] numbers) { int n = numbers.length; boolean[] b = new boolean[1000000]; int jokers = 0; for (int i = 0; i < n; i++) { if (numbers[i] == 0) jokers++; else b[numbers[i]] = true; } int max = 0; int count; int jokersUsed = 0; for (int i = 0; i < 1000000; i++) { count = 0; //int j = i; if (jokers > 0) jokersUsed = 0; else jokersUsed = 1000000; for (int j = i; j < 1000000; j++) { if (b[j]) count++; else { if (jokers > jokersUsed) { count++; jokersUsed++; } else break; } } if (count > max) max = count; } return max; } }