ouyangwanbin
BAN USERpublic static void findPythagorean(int[] arr){
int len = arr.length;
for(int i=0 ; i < len-2 ; i++){
for(int j=i+1; j < len-1;j++){
for(int k=j+1 ; k < len ; k++){
if(arr[i]*arr[i] + arr[j]*arr[j] == arr[k]*arr[k]){
System.out.println(arr[i] + "," +arr[j] + ","+arr[k]);
}
}
}
}
}
public static void reverseLinkedList(LinkedList<Integer> list){
while(list.size()>0){
System.out.println(list.removeLast());
}
}
/**
*
* @param arc sorted the array
* @param angular
* @return sub-array which contains the max elements in the array
*/
public static Queue<Integer> getMaxIntArr(int[] arc , int angular){
Queue<Integer> tempQue = new LinkedList<Integer>();
Queue<Integer> resultQue = new LinkedList<Integer>();
tempQue.add(arc[0]);
for(int i=1 ; i < arc.length ; i++){
if(getTempQueArcTotal(tempQue) <= angular){
tempQue.add(arc[i]);
if(resultQue.size() < tempQue.size()){
resultQue.clear();
resultQue.addAll(tempQue);
}
if(getTempQueArcTotal(tempQue) > angular){
resultQue.remove(arc[i]);
}
}
while(getTempQueArcTotal(tempQue) > angular){
tempQue.remove();
}
}
return resultQue;
}
/**
* @description get the sum angular in the queque
* @param que
* @return
*/
public static int getTempQueArcTotal(Queue<Integer> que){
Queue<Integer> tempQ = new LinkedList<Integer>();
tempQ.addAll(que);
int result = 0;
int temp = tempQ.remove();
while(!tempQ.isEmpty()){
result+=tempQ.peek() - temp;
temp = tempQ.remove();
}
return result;
}
may be this is more than O(n).
public static String reverseStringRecursion(String str){
- ouyangwanbin September 01, 2013if(str.length() == 1){
return str;
}
return (reverseStringRecursion(str.substring(1)) + str.charAt(0));
}