540. Single Element in a Sorted Array Medium
1/**
2 * [540] Single Element in a Sorted Array
3 *
4 * You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once.
5 * Return the single element that appears only once.
6 * Your solution must run in O(log n) time and O(1) space.
7 *
8 * Example 1:
9 * Input: nums = [1,1,2,3,3,4,4,8,8]
10 * Output: 2
11 * Example 2:
12 * Input: nums = [3,3,7,7,10,11,11]
13 * Output: 10
14 *
15 * Constraints:
16 *
17 * 1 <= nums.length <= 10^5
18 * 0 <= nums[i] <= 10^5
19 *
20 */
21pub struct Solution {}
22
23// problem: https://leetcode.com/problems/single-element-in-a-sorted-array/
24// discuss: https://leetcode.com/problems/single-element-in-a-sorted-array/discuss/?currentPage=1&orderBy=most_votes&query=
25
26// submission codes start here
27
28impl Solution {
29 pub fn single_non_duplicate(nums: Vec<i32>) -> i32 {
30 0
31 }
32}
33
34// submission codes end
35
36#[cfg(test)]
37mod tests {
38 use super::*;
39
40 #[test]
41 fn test_540() {
42 }
43}
44
Back
© 2025 bowen.ge All Rights Reserved.