zoukankan      html  css  js  c++  java
  • 去除重复记录

    String[] arrstr = new String[] { "1", "2", "3", "2", "3", "4", "5", "6", "1", "7", "8", "2", "3", "4", };
    /// <summary>
       
    /// 移除数组中重复的项
       
    /// </summary>
       
    /// <param name="arr"></param>
       
    /// <returns></returns>
        private Hashtable RemoveSame(String[] arr)
        {
            Hashtable ht
    = new Hashtable();
           
    for (int i = 0; i < arr.Length; i++)
            {
               
    if (ht[arr[i].ToString()] == null)
                {
                    ht[arr[i].ToString()]
    = arr[i];
                }
            }
           
    return ht;
        }
     
     
    /// <summary>
       
    /// 移除数组中重复的项
       
    /// </summary>
       
    /// <param name="arr"></param>
       
    /// <returns></returns>
        private ArrayList RemoveSame(String[] arr)
        {
            Hashtable ht
    = new Hashtable();
      ArrayList al=new ArrayList ();
           
    for (int i = 0; i < arr.Length; i++)
            {
               
    if (ht[arr[i].ToString()] == null)
                {
                    ht[arr[i].ToString()]
    = arr[i];
        al.add(arr[i]);
                }
            }
           
    return al;
        }

    RemoveSame(arrstr);
  • 相关阅读:
    LeetCode15 3Sum
    LeetCode10 Regular Expression Matching
    LeetCode20 Valid Parentheses
    LeetCode21 Merge Two Sorted Lists
    LeetCode13 Roman to Integer
    LeetCode12 Integer to Roman
    LeetCode11 Container With Most Water
    LeetCode19 Remove Nth Node From End of List
    LeetCode14 Longest Common Prefix
    LeetCode9 Palindrome Number
  • 原文地址:https://www.cnblogs.com/xsmhero/p/1621108.html
Copyright © 2011-2022 走看看