Julie
BAN USER
public static int[] findMaxSubSet(int[] array){
int max = 0;
int startKey = 0;
int tempCnt = 0;
int[] maxSub = null;
for(int i=1; i<array.length; i++){
if(array[i]-array[i-1] == 1) {
tempCnt++;
} else {
if(max <= tempCnt) {
max = tempCnt;
maxSub = Arrays.copyOfRange(array, startKey, i);
}
startKey = i;
tempCnt = 0;
}
}
return maxSub;
}
public static int[] removeDuplication(int[] array){
int[] maxSub = new int[array.length];
int temp = -1;
int tempKey = 0;
for(int a:array) {
if(temp != a) {
maxSub[tempKey] = a;
tempKey++;
}
}
return maxSub;
}
public static void main(String[] args) {
//Sort (O(logn))
int[] array = {1, 6, 10, 4, 7, 7, 9, 5};
QuickSort qsort = new QuickSort(array.length);
qsort.setArray(array);
qsort.quickSort(0, array.length-1);
array = qsort.getArray();
//find subset (O(n))
int[] maxSub = findMaxSubSet(array);
maxSub = removeDuplication(maxSub);
System.out.println(maxSub);
}
public class Compressor {
static StringBuffer compressed = new StringBuffer();
public static void main(String[] args) {
String original = "AAAABBBCXYZEEEEPPPPPKKABC";
charCount(original);
System.out.println(compressed);
}
public static void addString(char c, int cnt){
if(cnt == 1)
compressed.append(Character.toString(c));
else
compressed.append(Character.toString(c) + Integer.toString(cnt));
}
public static void charCount(String str){
str += " ";
Character temp = null;
int cnt = 0;
for(int i=0; i<str.length(); i++) {
if(temp == null) {
temp = str.charAt(i);
cnt = 1;
} else if(!temp.equals(str.charAt(i)) || i==str.length()-1){
addString(str.charAt(i-1), cnt);
temp = str.charAt(i);
cnt = 1;
} else {
cnt++;
}
}
}
}
/*
* compare ith char from 0 to i with (legnth -i)th char from length to length-i
* i = 0 to n/2
* */
public boolean process(String s){
char [] array = s.toCharArray();
for(int i=0; i<(array.length)/2; i++){
if(array[i] != array[array.length-i-1])
return false;
}
return true;
private static void interSwap(){
String[] array = {"a1","a2","a3", "a4", "a5", "b1", "b2", "b3","b4","b5"};
for(int i=0; i<array.length/2-1; i++) {
int m = array.length/2 - i;
for(int j=0; j<i+1; j++) {
String temp = array[m];
array[m] = array[m-1];
array[m-1] = temp;
m = m+2;
}
}
}
n 0 1 2 3 4
value -1 1 3 -2 2
1. define boolean inProcess = false;
2. From 0 to n, if value(n) = negative, continue
else
inProcess = true;
tempA = n;
while(inProcess) {
if(value[n] = negative)
inProcess = false;
tempB = value(n+1)
shift value(n) from n to n+1
increase n until find a negative value (m).
}
value[tempA] = tempB;
int[] array = {-1, 1, 3, 4, -2, 2};
boolean inProcess = false;
while(i<array.length) {
if(array[i] < 0) {
i++;
} else {
inProcess = true;
tempNo = i;
while(inProcess) {
if(tempB == null)
tempA = array[i];
else
tampA = tempB;
tempB = array[i+1];
if(array[i+1] < 0)
inProcess = false;
array[i+1] = tempA;
i++;
}
array[tempNo] = tempB;
}
}
Repjuanitajboon, Applications Developer at 247quickbookshelp
Hi everyone, I am from Pelham. I currently work in the Hechinger as Cashier.I like to do creative things ...
Repdalejohnson762, Accountant at ABC TECH SUPPORT
I have exceptionally skilled Journalists possessed dogged determination to find the new story and deliver it to the public. I ...
Repkristinedavila9, Android Engineer at ABC TECH SUPPORT
I am Kristine Davila Professor and director at Clinical Psychology. Having experience of 6 years in my career. I have ...
Reparlinenwalters, Software Analyst at ASAPInfosystemsPvtLtd
I Performed extensive web research to collect pertinent data and gather images related to the assigned articleIts act of writing ...
Repellenabeaudry4, Analyst at Boomerang Commerce
I'm a 23 year-old blogger, make-up junkie and follower of Hinduism.I love Reading because it brings happiness for ...
Repbrigidfwindle, Android Engineer at A9
I am able to communicate clearly and have a friendly disposition and a positive attitude. I am passionate about exploring ...
Open Chat in New Window
- Julie March 01, 2015