赞
踩
- public class Solution {
- public int singleNumber(int[] nums)
- {
- HashMap<Integer, Integer> map = new HashMap<>();
- Integer key = null;
- for (int i = 0; i < nums.length; i++)
- {
- if (!map.containsKey(nums[i]))
- {
- map.put(nums[i], i);
- }
- else
- {
- map.remove(nums[i]);
- }
- }
-
- Set<Integer> setKey = map.keySet();
- Iterator<Integer> iterator = setKey.iterator();
- // 从while循环中读取key
- while (iterator.hasNext())
- {
- key = iterator.next();
- // 此时的String类型的key就是我们需要的获取的值
- }
-
- return key;
-
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。