LeetCode 71. Simplify Path

CHIP-Seq数据分析流程 文章目录CHIP-Seq数据分析流程相关软件安装数据下载将SRA转化为fastq文件数据质控,过滤数据质控然后进行质控,过滤低质量reads,去接头比对下载小鼠参考基因组的索引和注释文件比对sam文件转bam为bam文件建立索引载入IGV查看用MACS call peak安装MACS结果注释与可视化 CHIP-Seq数据分析流程 相关软件安装 所需要的软件有sratoolkit, fastqc,bowtie2,samtools,macs2,htseq-count,bedtools和前面RNA-seq数据分析 阅读详情

LeetCode 71. Simplify Path

本博客转载自:https://blog.youkuaiyun.com/makuiyu/article/details/44497901
Solution1:没理解啥意思,只能抄别人的答案了
这道题的要求是简化一个Unix风格下的文件的绝对路径。

字符串处理,由于”..”是返回上级目录(如果是根目录则不处理),因此可以考虑用栈记录路径名,以便于处理。需要注意几个细节:
重复连续出现的’/’,只按1个处理,即跳过重复连续出现的’/’;
如果路径名是”.”,则不处理;
如果路径名是”..”,则需要弹栈,如果栈为空,则不做处理;
如果路径名为其他字符串,入栈。
最后,再逐个取出栈中元素(即已保存的路径名),用’/’分隔并连接起来,不过要注意顺序呦。
时间复杂度:O(n)
空间复杂度:O(n)

class Solution {
public:
    string simplifyPath(string path) {
         stack<string> ss; // 记录路径名
         for(int i = 0; i < path.size(); ) {
             // 跳过斜线'/'
             while (i < path.size() && '/' == path[i]) ++i;
             // 记录路径名
             string s = "";
             while (i < path.size() && path[i] != '/') s += path[i++];
             // 如果是".."则需要弹栈,否则入栈
             if (".." == s && !ss.empty())
                 ss.pop();
             else if (s != "" && s != "." && s != "..")
                 ss.push(s);
         }
         // 如果栈为空,说明为根目录,只有斜线'/'
         if (ss.empty())
             return "/";
         // 逐个连接栈里的路径名
         string s = "";
         while (!ss.empty()) {
             s = "/" + ss.top() + s;
             ss.pop();
         }
         return s;
     }
};
[基于STM32底盘控制与ROS上层导航小车制作] 第一节 stm32电机驱动与编码器读取反馈 系列文章目录 第一节stm32电机驱动与编码器读取反馈 第二节 stm32电机pid控制 第三节 stm32线速度标定 第四节 stm32添加mpu6050得到angle角度 第五节 实现STM32与ubuntu系统下的ROS串口DMA通信,传输底盘速度等信息 第六节 ROS计算和发布里程计 提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档 目录 系列文章目录 前言 1.pwm与电机正反转 2.编码器初始化 二、pwm控制与编码器使用 1.pwm使电机 . 阅读详情

相关推荐

【黑马点评】项目知识点及面经整理

【黑马点评】项目知识点及面经整理

m0_52031708的博客 6602

LeetCode刷题:71. Simplify Path

LeetCode刷题:71. Simplify Path 原题链接:https://leetcode.com/problems/simplify-path/ Given an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the canonical path. In a...

梅森上校的博客 业精于勤荒于嬉,形成于思毁于随。 308

ANSYS Help USER300

USER 300概述单元描述输入数据假设与限制条件 概述 单元描述 Mechanical APDL提供了一种方便的方法来创建自定义的单元,命名为USER300,可以创建几乎任何单元类型。 UserElem子程序为Mechanical APDL在单元类型创建上提供了一个接口,可传递用户自定义单元创建时所需的所有数据,然后从自定义单元返回所有数据和结果,以更新数据库和文件。因为通过接口可以访问数据库和文件信息,所以很少需要了解Mechanical APDL数据库程序和文件结构。该接口还提供了获取Mechanic

weixin_47019765的博客 2232

【LeetCode】71. Simplify Path 解题报告(Python)

【LeetCode】71. Simplify Path 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.me/ 题目地址:https://leetcode.com/problems/simplify-path/descr...

负雪明烛 2812

保姆级教程:用ArcGIS Pro搞定云南30米分辨率DEM地形图(附数据下载与配色方案)

本文提供了一份详细的ArcGIS Pro教程,指导用户如何制作云南30米分辨率DEM地形图。从数据下载、预处理到镶嵌与质量控制,再到地形分析与可视化,全流程覆盖云南复杂地形的处理要点。特别包含数据下载链接、配色方案及常见问题解决方案,适合地理信息分析新手和专业人士。

weixin_30467199的博客 309

如何运用好DeepSeek为自己服务:智能增强的范式革命 || 目录

1.1 认知增强的三次浪潮1.2 DeepSeek认知增强模型1.3 人机认知耦合协议1.4 认知增强的数学基础。

𝓓𝓸𝓶𝓲𝓷𝓪𝓽𝓲𝓷𝓰 𝓐𝓵𝓵 𝓣𝓱𝓲𝓷𝓰𝓼 1218

LeetCode71——Simplify Path

LeetCode71——Simplify Path 依然是恶心的字符串处理,倒不是有多难,是你不知道他有哪些Sample Input,你得把所有的情况考虑进去。。。 我在做的时候就没有考虑非法输入,也就是说,我默认认为给定的输入都是合法的路径名。。。 但是题目会给出/home///near/ 这种非法路径输入,或者是 /home/zhangxiao/.../ 这种,非常恶心。。。

上善若水 1028

AI爬虫:一文讲通AI爬虫技术和原理,及34个AI爬虫工具推荐

AI 爬虫 是一种结合了传统网络爬虫技术和人工智能(AI)技术的工具,能够更智能、高效地从网页中提取和处理数据。与传统爬虫相比,AI 爬虫能够更好地处理动态内容、复杂网页结构以及非结构化数据,同时具备数据清洗、分类、情感分析等高级功能。

数据知道的博客 1万+

LeetCode 71. Simplify Path(栈)

题目来源:https://leetcode.com/problems/simplify-path/ 问题描述 71.Simplify Path Medium Given anabsolute pathfor a file (Unix-style), simplify it. Or in other words, convert it to thecanonical path. ...

da_kao_la的博客 185

最新2026年《网络数据安全风险评估办法》条款解读

大型企业集团IT变革下的零信任安全体系建设方案(55页).pptx。以数据安全为核心的安全立体防御体系解决方案(41页).pptx。让数据安全合规地创造价值(15页 PPT).pptx。大型集团数据安全应急预案(57页).docx。数据安全治理与评估服务业务介绍.pptx。数据安全管理实践(17页).pptx。大数据安全架构设计方案.pptx。大数据安全规划总体方案.pptx。数据库安全综合治理方案.pptx。医疗数据安全建设方案.pptx。数据安全框架规划图.pptx。数据安全治理方案.pptx。

cdfunlove的博客 46

【LLC快速上手系列】LLC轻载时:开关频率 + 死区时间 联合优化!

轻载优化,频率别飞天,死区要有耐心。两手一起抓,效率高到笑。😎。

weixin_43199439的博客 1182

python写算法题:leetcode: 71. Simplify Path

class Solution(object): def simplifyPath(self, path): """ :type path: str :rtype: str """ paths=path.split('/') outpath=[] for p in paths: ...

194

史上最全工商银行核心系统建设历程:从“数据集中”到“ECOS”2.0,见证银行业信息科技跨时代发展征程

ECOS工程的直接成果是建成了工商银行第五代信息系统,即从单一核心银行系统到去核心化开放生态系统,率先开启了以智能化、开放化为特征,数据驱动引领经营模式变革,创新提出了一整套国际领先的分布式开放生态银行系统建设方案,在大型银行全分布式系统架构、主机下移、银行系统生态化转型、大规模交易型分布式数据库等多个领域再次实现“0到1”的突破,建成了具备国际领先水平的全分布式开放生态银行系统,继续勇立数字化转型潮头,推动高质量发展再上新台阶。工商银行的业务连续性管理水平实现了跨越式发展,有力地保障了业务发展。

银行信息系统应用架构详解 824

Leetcode 71 Simplify Path

Leetcode 71 Simplify Path Approach: Using Stacks Stack<String> stack = new Stack<String>(); String[] components = path.split("/"); Stack<String> stack = new Stack<String>(); ...

weixin_43876597的博客 164

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

LeetCode 71 Simplify Path

LeetCode 71 Simplify Path Problem Description: 简化输入的绝对路径 具体的题目信息: https://leetcode.com/problems/simplify-path/description/ Attention: (1)/home/..abvh简化后仍是/home/..abvh (2)/home/…简化后仍是/home/… ...

萤火虫啊飞呀飞 211

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

LeetCode71 Simplify Path java题解

题目: Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", => "/home" path = "/a/./b/../../c/", => "/c" 题解: 解题思路:这题是简化目录,每一级目录前面都有一个斜杠,我可以首先对斜杠进行分割,分割之后

u012249528的专栏 1970

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

LeetCode71 Simplify Path

LeetCode71 Simplify Path问题描述Given an absolute path for a file (Unix-style), simplify it.For example, path = “/home/”, =>“/home”path = “/a/./b/../../c/”, => “/c”简单分析这道题就是简化路径,看到这个路径我就想到了坑爹的windows系列路径分

yanqinghe123的专栏 324

【Leetcode】71. Simplify Path

题目地址: https://leetcode.com/problems/simplify-path/ 给定一个代表目录的字符串,返回其最终的真实目录。用栈来模拟整个过程即可。先将整个字符串按照"/“切割,这样切割所得就是所有的目录以及“.”本级目录和”…“上级目录。遇到”…"的时候,如果栈不空,就pop;遇到“.”的时候略过;除此之外说明是文件夹,就直接入栈。但最后输出目录的时候,要注意从栈底元素...

数学、算法爱好者的博客 237

leetcode No71. Simplify Path

Question: Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", => "/home" path = "/a/./b/../../c/", => "/c" Corner Cases: Did you consider the cas

Dufre 1007

LeetCode 71. Simplify Path【Java】

题目描述 71. 简化路径 AC代码 class Solution { public String simplifyPath(String path) { path+='/'; String res="",s=""; for(char c:path.toCharArray()){ if(res.isEmpty()) res+=c; else if(c!='/') s+=c; els

NayelyA的博客 227

Leetcode71- Simplify Path

1. 题目: 给定一个Unix系统下的路径,简化这个路径。 如 /home/ ,简化后为 /home 如 /a/./b/../../c/ ,简化后为 /c 2. 思路: 这还是一个入栈出栈匹配问题 构造无效字符集合 = {"",".",".."} 将字符串split成字符串数组 遍历字符串数组{ 如果元素等于“..”且栈不为空 出栈一个元素 如果元素不

sheldonwong的专栏 264

LeetCode-71 Simplify Path

Description Given an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the canonical path. In a UNIX-style file system, a period . refers to the current directory. Furthermore, a double period . .moves the directory up a

秦智慧的博客 186

【LeetCode】71. Simplify Path

问题描述https://leetcode.com/problems/simplify-path/#/descriptionGiven an absolute path for a file (Unix-style), simplify it.For example path = "/home/", => "/home" path = "/a/./b/../../c/", => "/c"Corne

zgljl2012的专栏 1037

【Leetcode】71 Simplify path 简化路径

Simplify path1. 题目——来自leetcode Given an absolute path for a file (Unix-style), simplify it. For example, path = “/home/”, => “/home” path = “/a/./b/../../c/

LYZ 813

leetcode 71 Simplify Path

题目连接 https://leetcode.com/problems/simplify-path/ Simplify Path Description Given an absolute path for a file (Unix-style), simplify it. For example,path="/home/", =>"/home"path="/a...

dong12276的博客 145

[leetcode] 71. Simplify Path

Description Given an absolute path for a file (Unix-style), simplify it. Or in other words, convert it to the canonical path. In a UNIX-style file system, a period . refers to the current directory. F...

Learning from the mistakes 210
上一篇: 【DFS】LeetCode 52. N-Queens II
下一篇: LeetCode 20. Valid Parentheses
Allenlzcoder
博客等级 码龄10年 925粉丝 512原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值