BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / acm-icpc / #90363同步于 2016/6/10
该镜像源已超过 30 天没有更新,可能在源站已被删除。
ACM_ICPC机器人发帖

请教一道Leetcode的medium题,无法识别字符串中的“\”

silenceTYN
2016/6/10镜像同步5 回复
3. Longest Substring Without Repeating Characters Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is "b", with the length of 1. Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring. 我的JAVA代码: public class Solution { public int lengthOfLongestSubstring(String s) { if(s.length() == 0) return s.length(); int max = 1; for(int i = 0; (i+1)<s.length(); i++){ int j = i+1; int count = 1; while(j < s.length() && !s.substring(i,i+1).equals(s.substring(j,j+1)) ){ boolean dup = false; int tempI = i+1; while(tempI < j){ if(s.substring(tempI, tempI+1).equals(s.substring(j,j+1))){ dup = true; break; } tempI ++; } if(dup == true) break; count ++; j ++; } if(count > max) max = count; } return max; } } 正常字符串或者带?,.的都没问题,但无法处理像“\qwertq”这样的带了“\”的字符。。过不了testcase。。 求大神解答~~谢谢~~~ [ema20][ema20][ema20][ema20]
订阅后,新回复会通过你的通知中心匿名送达。
5 条回复
liyi5133机器人#1 · 2016/6/10
这个用例是楼主编的吗? \是转义符,想输入字符“\”的话得再加个转义符“\\” 【 在 silenceTYN 的大作中提到: 】 : 3. Longest Substring Without Repeating Characters : Given a string, find the length of the longest substring without repeating characters. : Examples: : ...................
silenceTYN机器人#2 · 2016/6/10
感谢回复。是题目的test case,我这个还是个简化版的… 【 在 liyi5133 的大作中提到: 】 : 这个用例是楼主编的吗? : \是转义符,想输入字符“\”的话得再加个转义符“\\” : : 【 在 silenceTYN 的大作中提到: 】 : : 3. Longest Substring Wit : ......... 发自「贵邮」
changgong机器人#3 · 2016/6/22
不用java好长时间了,但是感觉需要转义吧
Ecxodia机器人#4 · 2016/7/3
我这个test case也过不了,但是却能accepted。。。
qmh2014机器人#5 · 2016/7/27
java String 里的/ 得写 "//"