Seller agent不肯告诉为什么卖房的原因为什么呢?# Living
m*o
1 楼
A non-empty zero-indexed array A consisting of N integers is given. A pair
of integers (P, Q) is called K-complementary in array A if 0 = P, Q < N and
A[P] + A[Q] = K.
For example, consider array A such that
A[0] = 1 A[1] = 8 A[2]= -3
A[3] = 0 A[4] = 1 A[5]= 3
A[6] = -2 A[7] = 4 A[8]= 5
1,8,-3,0,1,3,-2,4,5
The following pairs are 6-complementary in array A: (0,8), (1,6), (4,8), (5,
5), (6,1), (8,0), (8,4). For instance, the pair (4,8) is 6-complementary
because A[4] + A[8] = 1 + 5 = 6.
Write a function
class Solution { public int complementary_pairs(int K,int[] A); }
that, given an integer K and a non-empty zero-indexed array A consisting of
N integers, returns the number of K-complementary pairs in array A.
Assume that:
N is an integer within the range [1..50,000];
K is an integer within the range [-2,147,483,648..2,147,483,647];
-2147483648
2147483647
each element of array A is an integer within the range [-2,147,483,648..2,
147,483,647].
For example, given K = 6 and array A such that
A[0] = 1 A[1] = 8 A[2]= -3
A[3] = 0 A[4] = 1 A[5]= 3
A[6] = -2 A[7] = 4 A[8]= 5
the function should return 7, as explained above.
Complexity:
expected worst-case time complexity is O(N*log(N));
expected worst-case space complexity is O(N), beyond input storage (not
counting the storage required for input arguments).
Elements of input arrays can be modified.
In order to get the best score in the exercise, please read the information
below:
- Your code must compile. Failure to do so will yield a score of 0.
- Your algorithm must pass the *time* and *space* complexity indicated in
the programming exercise.
- Your score on the exercise is based on your algorithm being able to pass
the following the test cases:
- example1: example test
- extreme_all_equal: 4 equals elements (multiple runs)
- extreme_big_ints: big values (multiple runs)
- extreme_single: 1-element sequence (multiple runs)
- medium1: random array of size 1000
- medium1: random array of size 2000
- big1: random array of size 20000
- big2: random array of size 30000
- big3: random array of size 40000
Recommendations:
- Use the testing feature extensively to verify your algorithm against the
test cases above
of integers (P, Q) is called K-complementary in array A if 0 = P, Q < N and
A[P] + A[Q] = K.
For example, consider array A such that
A[0] = 1 A[1] = 8 A[2]= -3
A[3] = 0 A[4] = 1 A[5]= 3
A[6] = -2 A[7] = 4 A[8]= 5
1,8,-3,0,1,3,-2,4,5
The following pairs are 6-complementary in array A: (0,8), (1,6), (4,8), (5,
5), (6,1), (8,0), (8,4). For instance, the pair (4,8) is 6-complementary
because A[4] + A[8] = 1 + 5 = 6.
Write a function
class Solution { public int complementary_pairs(int K,int[] A); }
that, given an integer K and a non-empty zero-indexed array A consisting of
N integers, returns the number of K-complementary pairs in array A.
Assume that:
N is an integer within the range [1..50,000];
K is an integer within the range [-2,147,483,648..2,147,483,647];
-2147483648
2147483647
each element of array A is an integer within the range [-2,147,483,648..2,
147,483,647].
For example, given K = 6 and array A such that
A[0] = 1 A[1] = 8 A[2]= -3
A[3] = 0 A[4] = 1 A[5]= 3
A[6] = -2 A[7] = 4 A[8]= 5
the function should return 7, as explained above.
Complexity:
expected worst-case time complexity is O(N*log(N));
expected worst-case space complexity is O(N), beyond input storage (not
counting the storage required for input arguments).
Elements of input arrays can be modified.
In order to get the best score in the exercise, please read the information
below:
- Your code must compile. Failure to do so will yield a score of 0.
- Your algorithm must pass the *time* and *space* complexity indicated in
the programming exercise.
- Your score on the exercise is based on your algorithm being able to pass
the following the test cases:
- example1: example test
- extreme_all_equal: 4 equals elements (multiple runs)
- extreme_big_ints: big values (multiple runs)
- extreme_single: 1-element sequence (multiple runs)
- medium1: random array of size 1000
- medium1: random array of size 2000
- big1: random array of size 20000
- big2: random array of size 30000
- big3: random array of size 40000
Recommendations:
- Use the testing feature extensively to verify your algorithm against the
test cases above