-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHand_of_Straights.java
More file actions
53 lines (51 loc) · 1.26 KB
/
Hand_of_Straights.java
File metadata and controls
53 lines (51 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.*;
import java.io.*;
import java.lang.*;
public class Hand_of_Straights {
class Solution {
public boolean isNStraightHand(int[] hand, int groupSize) {
int n = hand.length;
if(n%groupSize!=0)
{
return false;
}
Arrays.sort(hand);
for(int i = 0 ; i<n ; i++)
{
if(hand[i]>=0)
{
if(!help(hand , groupSize , i , n))
{
return false;
}
}
}
return true;
}
private boolean help(int[] hand , int groupSize , int i , int n)
{
int next = hand[i] + 1;
hand[i] = -1;
int count = 1;
i = i+1;
while(i<n && count<groupSize)
{
if(hand[i] == next)
{
next = hand[i] + 1;
hand[i] = -1;
count++;
}
i++;
}
if (count != groupSize)
{
return false;
}
else
{
return true;
}
}
}
}