https://leetcode.com/problems/simplify-path/
来源:互联网 发布:漫画集软件 编辑:程序博客网 时间:2024/06/05 09:02
https://leetcode.com/problems/simplify-path/
还是比较简单的
1.以/为分隔符 将字符串分开
2.所有的 . 都变为‘’空串
3.所有的 .. 都变为‘’空串
并且把..前第一个不为空的串设置为空
因为..表示上一级
4.删除所有空串
5.用/再把串连起来 (如果只有空串 那么意味着是根目录 )
class Solution: # @param {string} path # @return {string} def simplifyPath(self, path): #没用过spilt 试试 list=path.split('/') for i in range(len(list)): if list[i]=='.': list[i]='' if list[i]=='..': list[i]='' for j in range(i+1)[::-1]: if list[j]!='': list[j]='' break #删除所有空串 sol=[] for i in list: if i!='': sol.append(i) solstr='' if sol==[]: solstr='/' else: for i in sol: solstr=solstr+'/'+i return solstr
0 0
- https://leetcode.com/problems/simplify-path/
- https://leetcode.com/problems/candy/
- https://leetcode.com/problems/sqrtx/
- https://oj.leetcode.com/problems/majority-element/
- https://leetcode.com/problems/longest-common-prefix/
- https://leetcode.com/problems/pascals-triangle/
- https://leetcode.com/problems/powx-n/
- https://leetcode.com/problems/reverse-integer/
- https://leetcode.com/problems/plus-one/
- https://leetcode.com/problems/unique-paths/
- https://leetcode.com/problems/palindrome-number/
- https://leetcode.com/problems/permutation-sequence/
- https://leetcode.com/problems/climbing-stairs/
- https://leetcode.com/problems/divide-two-integers/
- https://leetcode.com/problems/add-binary/
- https://leetcode.com/problems/add-two-numbers/
- https://leetcode.com/problems/merge-sorted-array/
- https://leetcode.com/problems/first-missing-positive/
- dot net程序逆向工程基本方法
- Java不用IDE工具时如何编译的
- js获取页面窗口大小
- open-vm-tools-dkms : 依赖: open-vm-tools (>= 2:9.4.0-1280544-5ubuntu3) 但是它将不会被安装
- 浅谈栈&&进制转换
- https://leetcode.com/problems/simplify-path/
- poj2456
- c++11的lambda入门总结
- jQuery之ajax归纳
- Mac下如何显示隐藏文件/文件夹
- 插入排序
- 设计模式之禅学习笔记--责任链模式
- 讲解SysWOW64文件夹
- IOS 遇到问题 记录