程序员达达

Java

[LeetCode] Single Number

Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? [思路] [常见错误] 1. [Code] public class Solution { public int singleNumber(int[] A) { final int undef = -999; int i, j; //…

[LeetCode] Remove Element

Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn’t matter what you leave beyond the new length. [思路] 注意题目要求,是要”in place”。可以使用”two pointers”的方法,遍历数组一遍。 [常见错误] 1. 注意数组为空的特殊情况 [Code] public class Solution { public int removeElement(int[] A, int elem) {…