arpitg
BAN USERpublic static Boolean funct(double[] arr) {
Integer count =0;
for(int i=0;i<arr.length; i++){
if(arr[i] < 2 ){
count++;
for(int j=i+1;j<arr.length; j++){
if(arr[j] < 2 && arr[i]+arr[j]< 2.0){
count++;
for(int x=j+1;x<arr.length; x++){
if(arr[i] < 2 ){
if(arr[i]+arr[j] + arr[x] <2.0 && arr[i]+arr[j] + arr[x] >= 1.0&& count ==2 ){
System.out.println(arr[i]);
System.out.println(arr[j]);
System.out.println(arr[x]);
x=arr.length;
return true;
}
}
}
j=arr.length;
}
}
i=arr.length;
}
}
return false;
}
//***************TEST EXAMPLE********************
public static void main(String[] args) {
double[] x={1,1.1,0.3,3,2,1,1,2,0.2,0.2,6,7};
Boolean b;
b=funct(x);
if(b == false)
System.out.println("Unable to find the sum of the triplet is in the range (1, 2)");
}
}
Arrange the array in descending order for eg n=4
4,3,2,1
(rotate the array 3 times i.e length(array)-1
3,2,1,4
2,1,4,3
1,4,3,2
Note leave the first element from (4,3,2,1) i.e take 3,2,1 (rotate the array 2 times i.e length(array)-1
4,2,1,3
4,1,3,2
Note leave the 2 elements from (4,3,2,1) i.e take 2,1 (rotate the array 1 times i.e length(remainingarray)-1
4,3,1,2
I think this should work
public static boolean checkAnagramV2(String str1, String str2){
if(str1.length() != str2.length())
return false;
else{
Integer val1 =0, val2=0;
for (int i=0;i<str1.length();i++)
{
val1 = (str1.charAt(i)-0) ^ val1;
val2 = (str2.charAt(i) -0) ^ val2;
}
if ((val1^val2) == 0)
return true;
else
return false;
}
}
@Anonymous on February 17, 2013
- arpitg February 17, 2013I have put iterations in and it never goes above o(n).. but if you want then replace j=arr.length; & i=arr.length with "return false"