cs: add «167. Two Sum II - Input Array Is Sorted»

URL:	https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2025-04-01 18:43:22 +02:00
parent d9fbfffbe2
commit 41a581431d
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View file

@ -0,0 +1,15 @@
public class Solution {
public int[] TwoSum(int[] numbers, int target) {
var (i, j) = (0, numbers.Length - 1);
while (i < j && numbers[i] + numbers[j] != target) {
if (numbers[i] + numbers[j] < target) {
++i;
} else {
--j;
}
}
return new int[] { i + 1, j + 1 };
}
}