leetcode -- 388. Longest Absolute File Path
来源:互联网 发布:收集区域手机号码软件 编辑:程序博客网 时间:2024/06/05 00:28
使用了一个map记录文件位置,o(n)的方案实现,没有出现额外的字符串匹配过程,4ms解决
func lengthLongestPath(input string) int { flag := make(map[int]int) tmp := 0 path := "" str := "" isFile := false max := 0 flag[-1] = 0 // maxStr := "" input += "\n" for i := 0; i < len(input); i++ { switch input[i] { case '\n': offset, ok := flag[tmp-1] if !ok { return -1 } path = path[0:offset] + str if !isFile { path += "/" } else { if len(path) > max { max = len(path) // maxStr = path } isFile = false } flag[tmp] = len(path) str = "" tmp = 0 case '\t': tmp++ case '.': isFile = true fallthrough default: str += string(input[i]) } } // println(maxStr, len(maxStr)) return max}
0 0
- LeetCode—388. Longest Absolute File Path
- LeetCode—388. Longest Absolute File Path
- leetcode -- 388. Longest Absolute File Path
- 388. [LeetCode]Longest Absolute File Path
- [Leetcode]388. Longest Absolute File Path
- 【LeetCode】 388. Longest Absolute File Path
- [LeetCode]388. Longest Absolute File Path
- LeetCode 388. Longest Absolute File Path
- [leetcode]388. Longest Absolute File Path
- leetcode:Longest Absolute File Path
- 【Leetcode】Longest Absolute File Path
- Leetcode Longest Absolute File Path
- 388. Longest Absolute File Path
- 388. Longest Absolute File Path
- 388. Longest Absolute File Path
- 388. Longest Absolute File Path
- 388. Longest Absolute File Path
- 388. Longest Absolute File Path
- ubuntu16.04+cuda7.5+caffe深度学习环境搭建
- Bootstrap 弹出框modal上层的输入框不能获得焦点问题
- javascript数组一些概念
- HtmlImageGenerator(Html2Image) 生成图片linux中文乱码
- Android存储
- leetcode -- 388. Longest Absolute File Path
- 修改系统textview的字体颜色
- ORA-01618: redo thread 2 is not enabled - cannot mount
- Shell脚本Ping监控主机是否存活并发邮件报警(三种方法)
- 018.View的Measure过程
- jar冲突
- Android TZ Keymaster
- day02运算及运算符,简单if swith for while dowhile语句数据结构
- MemSQL翻译第一天