na123092
BAN USERpublic static void maximumAscendingSequenceBoundary(int[] data)
{
for (int i = 0; i < data.length; i++) {
int lowerbound = i;
int middle = 0;
int upperbound = i;
int numberOfIntermediates = 0;
// find the upperbound of data[i]
for (int j = i+1; j < data.length; j++) {
if (data[i] < data[j] && data[j] > data[upperbound]) {
upperbound = j;
}
}
// if no upperbound is found then continue to the next lowerbound candidate
if (upperbound == 0) {
continue;
}
// if you find two better candidates between the lower and upper bound, cont
for (int j = i+1; j < upperbound; j++) {
if (data[j] > data[lowerbound] && data[j] < data[upperbound]) {
middle = j;
numberOfIntermediates++;
}
}
// if there is only one candidate between the lower and upper bound
if (numberOfIntermediates == 1) {
System.out.println(data[lowerbound] + ", " + data[middle] + ", " + data[upperbound]);
break;
}
}
}
package problemSets;
public class FirstNonRepeatingCharacter {
public static void main(String[] args) {
Character[] data = {'a','a','b','b','c','c','c','d','e','d'};
int j = 0;
int matches = 0;
for (int i = 0; i < data.length; i++) {
if (data[i] != data[j]) {
if (matches == 1) {
break;
} else {
data[j] = data[i];
matches = 1;
}
} else {
matches++;
}
}
System.out.println(data[j]);
}
}
- na123092 February 02, 2014