plduhoux
2/24/2018 - 5:59 PM

unusualDictionary

STILL BUGGY

boolean unusualDictionary(String[] wordList) {
    String[] spl = wordList[0].split(" ");
    String prev, prevart;
    if (spl.length == 2) {
        prev = spl[1];
        prevart = spl[0];
    } else {
        prev = wordList[0];
        prevart = null;
    }

    for (int i = 1; i < wordList.length; i++) {
        spl = wordList[i].split(" ");
        String cur, curart;
        if (spl.length == 2) {
            cur = spl[1];
            curart = spl[0];
        } else {
            cur = wordList[i];
            curart = null;
        }
        if (!rightOrder(prev, prevart, cur, curart)) {
            return false;
        }
        prev = cur;
        prevart = curart;
    }
    return true;
}
boolean rightOrder(String prev, String prevart, String cur, String curart) {
    if (cur.compareTo(prev) > 0) return true;
    else if (cur.compareTo(prev) == 0) {
        if (prevart == null && curart == null) return true;
        else if (prevart == null) return true;
        else if (curart == null) return false;
        else return curart.compareTo(prevart) >= 0;
    } else return false;
}