Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Find Sum in a sorted array
- int left = 0;
- int right = data.Length - 1;
- while(true)
- {
- if (left == right)
- {
- return false;
- }
- int tempSum = data[left] + data[right];
- if (tempSum == sum)
- {
- return true;
- }
- if (tempSum > sum)
- {
- --right;
- }
- else
- {
- ++left;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement