1.int[][]可以直接返回 定义 int [][]gridOut=new int[length][width];
2.二维数组不可以直接赋值给另一个,要每一行用clone()new[i]=old[i].clone;
否则只是赋值地址。
一维的System.arraycopy(src, srcPos, dest, destPos, length);
3.switch :
case :
break;
default:
;
4.boolean true false
5.hashmap
Map<Integer, Integer> map = new HashMap<>();//前key后值
map.put(nums[i], i);
(map.containsKey(complement) && map.get(complement)
class Solution {
public int[] twoSum(int[] nums, int target) {
int length=nums.length;
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < length; i++) {
map.put(nums[i], i);
}
for (int j = 0; j < length ; j++) {
int complement = target - nums[j];
if (map.containsKey(complement) && map.get(complement) != j) {
return new int[] { j, map.get(complement) };
}
}
throw new IllegalArgumentException("No two sum solution");
}
}