author: Blankj blog : http://blankj.com time : 2017/04/31 desc :
| 9 | * </pre> |
| 10 | */ |
| 11 | public 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected