442. Find All Duplicates in an Array Medium
1/**
2 * [442] Find All Duplicates in an Array
3 *
4 * Given an integer array nums of length n where all the integers of nums are in the range [1, n] and each integer appears once or twice, return an array of all the integers that appears twice.
5 * You must write an algorithm that runs in O(n) time and uses only constant extra space.
6 *
7 * Example 1:
8 * Input: nums = [4,3,2,7,8,2,3,1]
9 * Output: [2,3]
10 * Example 2:
11 * Input: nums = [1,1,2]
12 * Output: [1]
13 * Example 3:
14 * Input: nums = [1]
15 * Output: []
16 *
17 * Constraints:
18 *
19 * n == nums.length
20 * 1 <= n <= 10^5
21 * 1 <= nums[i] <= n
22 * Each element in nums appears once or twice.
23 *
24 */
25pub struct Solution {}
26
27// problem: https://leetcode.com/problems/find-all-duplicates-in-an-array/
28// discuss: https://leetcode.com/problems/find-all-duplicates-in-an-array/discuss/?currentPage=1&orderBy=most_votes&query=
29
30// submission codes start here
31
32impl Solution {
33 pub fn find_duplicates(nums: Vec<i32>) -> Vec<i32> {
34 vec![]
35 }
36}
37
38// submission codes end
39
40#[cfg(test)]
41mod tests {
42 use super::*;
43
44 #[test]
45 fn test_442() {
46 }
47}
48
Back
© 2025 bowen.ge All Rights Reserved.