public static boolean twoTwo(int[] nums) {
        boolean is = true;
        boolean nextIsTwo = false;
        boolean foundMate = false;

        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 2) {
                // Found 2

                // If in previous iteration we had a two...
                if (nextIsTwo) {
                    // ... then we found some mates.
                    foundMate = true;
                }
                // set for next iteration the two
                nextIsTwo = true;
            }
            else {
                // Found some other number.

                if (nextIsTwo) {
                    // If the element next to it is a two...
                    if (foundMate) {
                        // ...either it has a mate so everything's cool and
                        // reseting flags...
                        foundMate = false;
                        nextIsTwo = false;
                    }
                    else {
                        // ...or with no mate we have a problem.
                        is = false;
                        break;
                    }
                }
            }
        }

        // Test if the last element in the array is a
        // two without a mate.
        if(nextIsTwo && !foundMate) {
            is = false;
        }

        return is;
    }