How can I improve the performance of this algorithm

Posted by Justin on Stack Overflow See other posts from Stack Overflow or by Justin
Published on 2012-10-08T03:07:23Z Indexed on 2012/10/08 3:37 UTC
Read the original article Hit count: 112

Filed under:
|
|
// Checks whether the array contains two elements whose sum is s.
// Input: A list of numbers and an integer s
// Output: return True if the answer is yes, else return False

public static boolean calvalue (int[] numbers, int s){
for (int i=0; i< numbers.length; i++){
    for (int j=i+1; j<numbers.length;j++){
        if (numbers[i] < s){
            if (numbers[i]+numbers[j] == s){
                return true;
                }
            }
        }
    }
    return false;
}

© Stack Overflow or respective owner

Related posts about java

Related posts about Performance