-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSolution.cs
More file actions
25 lines (22 loc) · 870 Bytes
/
Solution.cs
File metadata and controls
25 lines (22 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
namespace LeetCodeNet.G0201_0300.S0283_move_zeroes {
// #Easy #Top_100_Liked_Questions #Array #Two_Pointers #LeetCode_75_Two_Pointers
// #Algorithm_I_Day_3_Two_Pointers #Programming_Skills_I_Day_6_Array #Udemy_Arrays
// #Big_O_Time_O(n)_Space_O(1) #2025_06_16_Time_1_ms_(96.12%)_Space_58.35_MB_(71.18%)
public class Solution {
public void MoveZeroes(int[] nums) {
int firstZero = 0;
for (int i = 0; i < nums.Length; i++) {
if (nums[i] != 0) {
Swap(firstZero, i, nums);
firstZero++;
}
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822", Justification = "LeetCode")]
private void Swap(int index1, int index2, int[] numbers) {
int val2 = numbers[index2];
numbers[index2] = numbers[index1];
numbers[index1] = val2;
}
}
}