zoukankan      html  css  js  c++  java
  • 217. 判断是数组否有重复元素 Contains Duplicate

    217. Contains Duplicate

    Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.


    1. public class Solution {
    2. public bool ContainsDuplicate(int[] nums) {
    3. int length = nums.Length;
    4. int num = 0;
    5. int value =0;
    6. Dictionary<int,int> d = new Dictionary<int,int>();
    7. for (int i = 0; i < length; i++) {
    8. num = nums[i];
    9. if (d.TryGetValue(num, out value)){
    10. return true;
    11. } else {
    12. d[num] = 1;
    13. }
    14. }
    15. return false;
    16. }
    17. }





  • 相关阅读:
    继承与多态
    本周总结
    总结
    周总结
    周总结
    第三周总结
    .......
    .....
    ....
    ....
  • 原文地址:https://www.cnblogs.com/xiejunzhao/p/4a13ae9b8b706dafa49534aeaf427ae4.html
Copyright © 2011-2022 走看看