Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

JavaBat

Name: Jesus 2009-02-11 20:37

Hey /programing/ i need some help w/ javabat.(array 1)

it would really help if i could have the user/pass of someones. i will not screw it up.




We'll say that a 1 immediately followed by a 3 in an array is an "unlucky" 1. Return true if the given array contains an unlucky 1 in the first 2 or last 2 positions in the array.

unlucky1({1, 3, 4, 5}) → true
unlucky1({2, 1, 3, 4, 5}) → true
unlucky1({1, 1, 1}) → false
public boolean unlucky1(int[] nums) {

Name: Anonymous 2009-02-11 22:51

Here you go OP, don't mind these trolls.

public boolean unlucky(int[] nums) {
    if(nums.length<=1) return false;
    int last = nums[0];
    for(int i=1; i<nums.length; i++) {
        int cur = nums[i];
        if(cur==3 && last==1) {
            return true;
        }
        last = cur;
    }
}


Hasn't been checked so there might be something small wrong.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List