5月18号

  一、保持数组中的每个元素与其索引相互对应的最好方法是什么?哈希表【来源LK】

    1. map.containsKey(complement):Map集合集合中包含这个key么,返回值是boolean。

    2. map.get(complement):Map集合中根据key获取值value.返回值是value。

    3.所谓hash表就是Map集合。

      

    class Solution {

    public int[] twoSum(int[] nums, int target) {

    Map<Integer, Integer> map = new HashMap<>();
    for (int i = 0; i < nums.length; i++) {
    int complement = target - nums[i];
    if (map.containsKey(complement)) {
    return new int[] { map.get(complement), i };
    }
    map.put(nums[i], i);
    }
    throw new IllegalArgumentException("No two sum solution");

    }}

二 、

  1. Integer.MAX_VALUE

      :java int 类整数的最大值是 2 的 31 次方 - 1 = 2147483648 - 1 = 2147483647

      :Integer.MAX_VALUE + 1 = Integer.MIN_VALUE = -2147483648

Java 八种基本类型 中表示整数的有:byte、short、int、long 这四种。  (另外四种是 float、double、char、boolean)

三、

  1. List是队列。

  

猜你喜欢

转载自www.cnblogs.com/wym591273/p/10885950.html
518