diff options
author | Jack Sangdahl <[email protected]> | 2025-06-27 12:23:02 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-06-27 12:23:02 -0600 |
commit | a96b65cbfad7f62f3db6b2eab105e4e25c0414c5 (patch) | |
tree | e2a2b3f49f9fb741be81415266ac93e74cff42ec /other/single_element_sorted_arr.cpp | |
parent | 694ad5ed71edcb1deccab54b72d706b779918276 (diff) | |
download | leetcode-a96b65cbfad7f62f3db6b2eab105e4e25c0414c5.tar.gz leetcode-a96b65cbfad7f62f3db6b2eab105e4e25c0414c5.zip |
chore: remove old cpp and rust solutions
Diffstat (limited to 'other/single_element_sorted_arr.cpp')
-rw-r--r-- | other/single_element_sorted_arr.cpp | 33 |
1 files changed, 0 insertions, 33 deletions
diff --git a/other/single_element_sorted_arr.cpp b/other/single_element_sorted_arr.cpp deleted file mode 100644 index e9bd894..0000000 --- a/other/single_element_sorted_arr.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// 540. Single Element in a Sorted Array -#include "leetcode.h" - -/* - * given a sorted array consisting of only integers where very element appears - * exactly twice, except for one element which appears exactly once. return the - * single element that appears only once. solution func must be o(ln) time and - * o(1) space complexity. - */ - -class Solution { -public: - int singleNonDuplicate(vector<int> &nums) { - int low = 0, high = nums.size() - 1, mid; - while (low < high) { - mid = (low + high) / 2; - if ((mid % 2 && nums[mid - 1] == nums[mid]) || - (!(mid % 2) && nums[mid] == nums[mid + 1])) - low = mid + 1; - else - high = mid; - } - return nums[low]; - } -}; - -int main() { - Solution obj; - vector<int> nums1 = {1, 1, 2, 3, 3, 4, 4, 8, 8}, - nums2 = {3, 3, 7, 7, 10, 11, 11}; - cout << obj.singleNonDuplicate(nums1) << endl; // expect: 2 - cout << obj.singleNonDuplicate(nums2) << endl; // expect: 10 -} |