题解 | #最长不重复子数组长度问题#

最长不重复子数组长度问题

https://www.nowcoder.com/practice/2b97599367784237aadac4de2008829d

using System;
using System.Collections.Generic;


class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param nums int整型一维数组 
     * @return int整型
     */
    public int longestUniqueSubarrayLength (List<int> nums) {
        // write code here
        List<int> res = new List<int>();
        int index = 0;
        List<int> uniqueNums = new List<int>();
        for(int i = 0; i < nums.Count; i++)
        {
            if(uniqueNums.Contains(nums[i]))
            {
                uniqueNums.Clear();
                index++;
            }
            else{
                uniqueNums.Add(nums[i]);
                if(res.Count<index+1)
                {
                    res.Add(0);
                }
                res[index]++;
            }
        }
        res.Sort();
        return res[res.Count - 1];
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-02 18:35
简历上把1个月实习写成了3个月,会进行背调吗?
码农索隆:一个月有一个月的实习经历,三个月有三个月的实习经历
点赞 评论 收藏
分享
点赞 评论 收藏
分享
06-12 16:00
天津大学 Java
牛客30236098...:腾讯坏事做尽,终面挂是最破防的 上次被挂了后我连简历都不刷了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务