Skip to content

Instantly share code, notes, and snippets.

@sckm
Last active January 1, 2016 16:59
Show Gist options
  • Save sckm/8173964 to your computer and use it in GitHub Desktop.
Save sckm/8173964 to your computer and use it in GitHub Desktop.
SRM601 Div2 mid
public int getNumber(int[] type)
{
Arrays.sort(type);
int res;
int lastNum;
int curNumCount;
int lastComb;
if(type[0] != 1)
return 0;
lastNum = 1;
res = 0;
lastComb = curNumCount = 1;
for(int i=1;i<type.length;i++){
if(lastNum == type[i]){
curNumCount++;
continue;
}else if(lastNum+1 == type[i]){
lastComb = lastComb * curNumCount;
res = res + lastComb;
lastNum++;
curNumCount=1;
}else{
lastComb = lastComb * curNumCount;
res = res + lastComb;
curNumCount=0;
break;
}
}
res = res + lastComb*curNumCount;
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment