题解 | #扑克牌顺子#
扑克牌顺子
http://www.nowcoder.com/practice/762836f4d43d43ca9deb273b3de8e1f4
using System;
using System.Collections.Generic;
class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param numbers int整型一维数组
* @return bool布尔型
*/
public bool IsContinuous (List<int> numbers) {
// write code here
int kingCout = 0;
int delta = 0;
numbers.Sort();
for(int i=0; i < numbers.Count; i++){
if(numbers[i]==0){
kingCout++;
}
}
for(int i=kingCout; i < numbers.Count-1; i++){
if(numbers[i] == numbers[i+1]){
return false;
}else{
delta+=(numbers[i+1]-numbers[i]-1);
}
}
return delta<=kingCout;
}
}
using System.Collections.Generic;
class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param numbers int整型一维数组
* @return bool布尔型
*/
public bool IsContinuous (List<int> numbers) {
// write code here
int kingCout = 0;
int delta = 0;
numbers.Sort();
for(int i=0; i < numbers.Count; i++){
if(numbers[i]==0){
kingCout++;
}
}
for(int i=kingCout; i < numbers.Count-1; i++){
if(numbers[i] == numbers[i+1]){
return false;
}else{
delta+=(numbers[i+1]-numbers[i]-1);
}
}
return delta<=kingCout;
}
}