3842. Toggle Light Bulbs Easy

@problem@discussion
#Array#Hash Table#Sorting#Simulation



1/**
2 * [3842] Toggle Light Bulbs
3 *
4 * You are given an array bulbs of integers between 1 and 100.
5 * There are 100 light bulbs numbered from 1 to 100. All of them are switched off initially.
6 * For each element bulbs[i] in the array bulbs:
7 * 
8 * 	If the bulbs[i]^th light bulb is currently off, switch it on.
9 * 	Otherwise, switch it off.
10 * 
11 * Return the list of integers denoting the light bulbs that are on in the end, sorted in ascending order. If no bulb is on, return an empty list.
12 *  
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: bulbs<span class="example-io"> = [10,30,20,10]</span>
16 * Output: <span class="example-io">[20,30]</span>
17 * Explanation:
18 * 
19 * 	The bulbs[0] = 10^th light bulb is currently off. We switch it on.
20 * 	The bulbs[1] = 30^th light bulb is currently off. We switch it on.
21 * 	The bulbs[2] = 20^th light bulb is currently off. We switch it on.
22 * 	The bulbs[3] = 10^th light bulb is currently on. We switch it off.
23 * 	In the end, the 20^th and the 30^th light bulbs are on.
24 * </div>
25 * <strong class="example">Example 2:
26 * <div class="example-block">
27 * Input: bulbs<span class="example-io"> = [100,100]</span>
28 * Output: <span class="example-io">[]</span>
29 * Explanation:
30 * 
31 * 	The bulbs[0] = 100^th light bulb is currently off. We switch it on.
32 * 	The bulbs[1] = 100^th light bulb is currently on. We switch it off.
33 * 	In the end, no light bulb is on.
34 * </div>
35 *  
36 * Constraints:
37 * 
38 * 	1 <= bulbs.length <= 100
39 * 	1 <= bulbs[i] <= 100
40 * 
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/toggle-light-bulbs/
45// discuss: https://leetcode.com/problems/toggle-light-bulbs/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50    pub fn toggle_light_bulbs(bulbs: Vec<i32>) -> Vec<i32> {
51        vec![]
52    }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn test_3842() {
63    }
64}
65

Back
© 2026 bowen.ge All Rights Reserved.