蔚来7.1号笔试题,第三个笔试题 HTML标签匹配 有无hxd给个答案。
#蔚来笔试#蔚来#
全部评论
https://www.nowcoder.com/discuss/977525
1 回复 分享
发布于 2022-07-02 11:58
就是**里面的有小括号题目的复杂化而已,原理是一样的 https://leetcode.cn/problems/valid-parentheses/
点赞 回复 分享
发布于 2022-07-02 11:26
随机输出yes和no,多提交几次,能过80%🤣
点赞 回复 分享
发布于 2022-07-01 21:57
go的,没有全部过,88%好像是 package main import ( "fmt" "strings" ) func main() { var s string fmt.Scan(&s) s_t := strings.Split(s, "><") var stack []string for i := 0; i < len(s_t); i++ { if strings.HasPrefix(s_t[i], "<") { s_t[i] = s_t[i][1:] } else if strings.HasSuffix(s_t[i], ">") { s_t[i] = s_t[i][:len(s_t[i])-1] stack = append(stack) } else { stack = append(stack, s_t[i]) } } if len(s_t) == 1 { fmt.Println("NO") return } for i := 0; i < len(s_t); i++ { if strings.HasPrefix(s_t[i], "/") { if len(stack) == 0 { fmt.Println("NO") return } else if stack[len(stack)-1] != s_t[i][1:] { fmt.Println("NO") return } else if stack[len(stack)-1] == s_t[i][1:] { stack = stack[:len(stack)-1] } } else { stack = append(stack, s_t[i]) } } fmt.Println("YES") }
点赞 回复 分享
发布于 2022-07-02 14:29
public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()) { String str = sc.next(); Deque<Character> stackCh = new ArrayDeque<>();//存 '<' Deque<StringBuilder> stackSB = new ArrayDeque<>();//存<>里面的字符串 int len = str.length(); int cur = 0; while (cur < len) { if (str.charAt(cur) == '<') { stackCh.push('<'); if (str.charAt(cur + 1) == '/') { if (stackSB.isEmpty()) { break; } cur += 2; StringBuilder sec = stackSB.poll(); int sbLen = sec.length(); String tmpStr = str.substring(cur, cur + sbLen); if (judgeStr(sec.toString(), tmpStr)) { cur += sbLen; if (str.charAt(cur) == '>') { cur++; continue; } else { break; } } else { break; } } else { cur++; char ch = str.charAt(cur); StringBuilder sb = new StringBuilder(); while (cur < len && ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))) { sb.append(ch); cur++; ch = str.charAt(cur); } if (sb.isEmpty()) break; stackSB.push(sb); } } else if (str.charAt(cur) == '>') { if (stackCh.isEmpty()) { break; } stackCh.poll(); cur++; } else { break; } } if (cur == len) { if(!stackSB.isEmpty()) { System.out.println("NO"); } else { System.out.println("YES"); } } else { System.out.println("NO"); } } } private static boolean judgeStr(String sec, String s) { int len1 = sec.length(), len2 = s.length(); if(len1 != len2) return false; for(int i = 0;i < len1;i++) { if(sec.charAt(i) != s.charAt(i)) { return false; } } return true; }
点赞 回复 分享
发布于 2022-07-02 15:59

相关推荐

01-18 09:26
已编辑
门头沟学院 Java
王桑的大offer:建议中间件那块写熟悉即可,写掌握 面试包被拷打到昏厥
点赞 评论 收藏
分享
评论
1
2
分享

创作者周榜

更多
牛客网
牛客企业服务