problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::simplify_path::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static string simplifyPath (const string &path)
 

详细描述

在文件 leetcode.h258 行定义.

成员函数说明

◆ simplifyPath()

string leetcode::simplify_path::Solution::simplifyPath ( const string &  path)
static

在文件 leetcode.cpp560 行定义.

560 {
561 auto *const str_cpy = new char[path.size() + 1];
562 memcpy(str_cpy, path.c_str(), path.size() + 1);
563 auto *next = strtok(str_cpy, "/");
564 auto stck = deque<string>();
565 while(next != nullptr) {
566 auto nextstr = string(next);
567 if(nextstr == "..") {
568 if(!stck.empty()) {
569 stck.pop_back();
570 }
571 next = strtok(nullptr, "/");
572 continue;
573 }
574 if(nextstr == ".") {
575 next = strtok(nullptr, "/");
576 continue;
577 }
578 stck.emplace_back(next);
579 next = strtok(nullptr, "/");
580 }
581 auto oss = ostringstream();
582 if(stck.empty()) {
583 oss << '/';
584 } else {
585 while(!stck.empty()) {
586 auto pname = stck.front();
587 oss << '/' << pname;
588 stck.pop_front();
589 }
590 }
591 delete[] str_cpy;
592 return oss.str();
593 }

被这些函数引用 leetcode::simplify_path::TEST().


该类的文档由以下文件生成: