MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / Solution

Class Solution

src/com/blankj/easy/_0027/Solution.java:11–30  ·  view source on GitHub ↗

author: Blankj blog : http://blankj.com time : 2017/04/31 desc :

Source from the content-addressed store, hash-verified

9 * </pre>
10 */
11public class Solution {
12 public int removeElement(int[] nums, int val) {
13 int tail = 0;
14 for (int i = 0, len = nums.length; i < len; ++i) {
15 if (nums[i] != val) {
16 nums[tail++] = nums[i];
17 }
18 }
19 return tail;
20 }
21
22 public static void main(String[] args) {
23 Solution solution = new Solution();
24 int[] data = new int[]{0, 3, 1, 1, 2, 3, 3, 3};
25 int len = solution.removeElement(data, 3);
26 for (int i = 0; i < len; i++) {
27 System.out.print(data[i] + (i == len - 1 ? "" : ", "));
28 }
29 }
30}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected