-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path27 Remove Element.cs
More file actions
106 lines (83 loc) · 2 KB
/
27 Remove Element.cs
File metadata and controls
106 lines (83 loc) · 2 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//27.Remove Element https://leetcode.cn/problems/remove-element/
//public class Solution // 5/22/2023 7:22 PM
//{
//// public int RemoveElement(int[] nums, int val)
//// {
//// if (nums.Length <= 1)
//// {
//// if (nums.Length == 0) return 0;
//// if (nums.Length == 1 && nums[0] == val) return 0;
//// else return 1;
//// }
// int n = 0;
// int i = 0;
// int c = nums.Length;
// while (i < nums.Length - 1)
// {
// if (nums[i] == val)
// {
// //i++;
// c--;
// //nums[n] = nums[i];
// }
// else
// {
// nums[n] = nums[i];
// n++;
// // i++;
// }
// i++;
// }
// if (nums[i] == val)
// {
// c--;
// if (c <= 0)
// return 0;
// else return n;
// }
// else { nums[n] = nums[i]; return c; }
// }
//}
//public class Solution //5/22/2023 8:47 PM
//{
// public int RemoveElement(int[] nums, int val)
// {
// int n = 0;
// List<int> list = nums.ToList();
// list.RemoveAll(x => x == val);
// foreach (int x in list)
// {
// //Console.WriteLine(x+" ");
// nums[n++] = x;
// }
// return list.Count;
// }
//}
//int RemoveElement(int[] nums, int val)
//{
// if (nums.Length <= 1)
// {
// if (nums.Length == 0) return 0;
// if (nums.Length == 1 && nums[0] == val) return 0;
// else return 1;
// }
// int n = 0;
// int i = 0;
// int c = nums.Length;
// while (i < nums.Length )
// {
// if (nums[i] == val)
// {
// // i++;
// c--;
// //nums[n] = nums[i];
// }
// else
// {
// nums[n] = nums[i];
// n++;
// //i++;
// }
// i++;
// }
// return c;