shein笔试 提交用例0%

class Solution {
    int res = Integer.MIN_VALUE;
	List<String> list = new ArrayList<>();
    public String[] lengthOfLongestSubstring(String input) {
        int len = s.length();
        if(len == 0) return null;
        if(len == 1) return new String[]{input};


        int start = 0;
	     Map<Character, Integer> map = new HashMap<>();
	        for (int i = 0; i < len; i++) {
	        	char ch = input.charAt(i);
	        	if (map.containsKey(ch)) {
	        		int index = map.get(ch);
	        		if (start <= index && index < len) {
	        			int temp = start;
	        			start = index + 1;
	        			int newLen = i - start + 1;
	        			if (newLen == res) {
	        				if (i != len - 1) list.add(input.substring(start, i + 1));
	        				else list.add(input.substring(start));
	        			}else if (newLen > res) {
	        				res = newLen;
	        				list = new ArrayList<>();
	        				if (i - temp == newLen) list.add(input.substring(temp, i));
	        				list.add(input.substring(start, i + 1));
	        			}
	        		}
	        	}
	        	map.put(ch, i);
	        }
	        
	        String temp = input.substring(start);
	        if (temp.length() > res) {
	        	res = temp.length();
	        	list = new ArrayList<>();
	        	list.add(temp);
	        }
	        
	  		if (res != Integer.MIN_VALUE) {
			  	String[] strs = new String[list.size()];
	        	for(int i = 0; i < list.size(); i++) {
	        	strs[i] = list.get(i);
	        	//System.out.println(strs[i]);
				return strs;
	        	}
			} else return null;
	  
			  
	        
	  		
    }
}

代码是结束之后自己重新敲的,可能有不一致的地方吧。

题目是力扣第三题 无重复字符的最长子串 改了一下,不再返回最长长度,返回达到最长长度的子字符串数组。

测试用例都过了,但是提交显示用例0%。玉玉了。

#我的实习求职记录#
全部评论
笔试时间是多久
点赞 回复 分享
发布于 2023-04-22 00:00 四川
sheIn还开着呢 我之前泡了大半个月池子,上个礼拜终于把我挂了
点赞 回复 分享
发布于 2023-04-22 16:29 浙江
什么岗位
点赞 回复 分享
发布于 2023-04-30 00:00 山西

相关推荐

昨天 13:52
门头沟学院 后端
给🐭🐭个面试机会吧:嘿,mvbatis
点赞 评论 收藏
分享
评论
点赞
2
分享

创作者周榜

更多
牛客网
牛客企业服务