Skip to content

Commit 3fdc517

Browse files
committed
71. Simplify Path
1 parent 923cf34 commit 3fdc517

10 files changed

+255
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// 71. Simplify Path.cpp : Defines the entry point for the console application.
2+
//
3+
4+
#include "stdafx.h"
5+
6+
#include <iostream>
7+
#include <string>
8+
#include <vector>
9+
#include <sstream>
10+
11+
using namespace std;
12+
13+
class Solution {
14+
public:
15+
string simplifyPath(string path) {
16+
vector<string> dirs;
17+
for (auto i = path.begin(); i != path.end();) {
18+
++i;
19+
auto j = find(i, path.end(), '/');
20+
auto dir = string(i, j);
21+
if (!dir.empty() && dir != ".") {// µ±ÓÐÁ¬Ðø'///' ʱ£¬dir Ϊ¿Õ
22+
if (dir == "..") {
23+
if (!dirs.empty())
24+
dirs.pop_back();
25+
}
26+
else
27+
dirs.push_back(dir);
28+
}
29+
i = j;
30+
}
31+
stringstream out;
32+
if (dirs.empty()) {
33+
out << "/";
34+
}
35+
else {
36+
for (auto dir : dirs)
37+
out << '/' << dir;
38+
}
39+
return out.str();
40+
}
41+
};
42+
43+
int main()
44+
{
45+
return 0;
46+
}
47+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
</ItemGroup>
13+
<PropertyGroup Label="Globals">
14+
<ProjectGuid>{56D11F29-656C-40F2-8B15-B06AA4DE7B0B}</ProjectGuid>
15+
<Keyword>Win32Proj</Keyword>
16+
<RootNamespace>My71SimplifyPath</RootNamespace>
17+
</PropertyGroup>
18+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
19+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
20+
<ConfigurationType>Application</ConfigurationType>
21+
<UseDebugLibraries>true</UseDebugLibraries>
22+
<PlatformToolset>v120</PlatformToolset>
23+
<CharacterSet>Unicode</CharacterSet>
24+
</PropertyGroup>
25+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
26+
<ConfigurationType>Application</ConfigurationType>
27+
<UseDebugLibraries>false</UseDebugLibraries>
28+
<PlatformToolset>v120</PlatformToolset>
29+
<WholeProgramOptimization>true</WholeProgramOptimization>
30+
<CharacterSet>Unicode</CharacterSet>
31+
</PropertyGroup>
32+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
33+
<ImportGroup Label="ExtensionSettings">
34+
</ImportGroup>
35+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
36+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
37+
</ImportGroup>
38+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
39+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
40+
</ImportGroup>
41+
<PropertyGroup Label="UserMacros" />
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
43+
<LinkIncremental>true</LinkIncremental>
44+
</PropertyGroup>
45+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
46+
<LinkIncremental>false</LinkIncremental>
47+
</PropertyGroup>
48+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
49+
<ClCompile>
50+
<PrecompiledHeader>Use</PrecompiledHeader>
51+
<WarningLevel>Level3</WarningLevel>
52+
<Optimization>Disabled</Optimization>
53+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
54+
<SDLCheck>true</SDLCheck>
55+
</ClCompile>
56+
<Link>
57+
<SubSystem>Console</SubSystem>
58+
<GenerateDebugInformation>true</GenerateDebugInformation>
59+
</Link>
60+
</ItemDefinitionGroup>
61+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
62+
<ClCompile>
63+
<WarningLevel>Level3</WarningLevel>
64+
<PrecompiledHeader>Use</PrecompiledHeader>
65+
<Optimization>MaxSpeed</Optimization>
66+
<FunctionLevelLinking>true</FunctionLevelLinking>
67+
<IntrinsicFunctions>true</IntrinsicFunctions>
68+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
69+
<SDLCheck>true</SDLCheck>
70+
</ClCompile>
71+
<Link>
72+
<SubSystem>Console</SubSystem>
73+
<GenerateDebugInformation>true</GenerateDebugInformation>
74+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
75+
<OptimizeReferences>true</OptimizeReferences>
76+
</Link>
77+
</ItemDefinitionGroup>
78+
<ItemGroup>
79+
<Text Include="ReadMe.txt" />
80+
</ItemGroup>
81+
<ItemGroup>
82+
<ClInclude Include="stdafx.h" />
83+
<ClInclude Include="targetver.h" />
84+
</ItemGroup>
85+
<ItemGroup>
86+
<ClCompile Include="71. Simplify Path.cpp" />
87+
<ClCompile Include="stdafx.cpp">
88+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
89+
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
90+
</ClCompile>
91+
</ItemGroup>
92+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
93+
<ImportGroup Label="ExtensionTargets">
94+
</ImportGroup>
95+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<Text Include="ReadMe.txt" />
19+
</ItemGroup>
20+
<ItemGroup>
21+
<ClInclude Include="stdafx.h">
22+
<Filter>Header Files</Filter>
23+
</ClInclude>
24+
<ClInclude Include="targetver.h">
25+
<Filter>Header Files</Filter>
26+
</ClInclude>
27+
</ItemGroup>
28+
<ItemGroup>
29+
<ClCompile Include="stdafx.cpp">
30+
<Filter>Source Files</Filter>
31+
</ClCompile>
32+
<ClCompile Include="71. Simplify Path.cpp">
33+
<Filter>Source Files</Filter>
34+
</ClCompile>
35+
</ItemGroup>
36+
</Project>

leetcode/71. Simplify Path/ReadMe.txt

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
========================================================================
2+
CONSOLE APPLICATION : 71. Simplify Path Project Overview
3+
========================================================================
4+
5+
AppWizard has created this 71. Simplify Path application for you.
6+
7+
This file contains a summary of what you will find in each of the files that
8+
make up your 71. Simplify Path application.
9+
10+
11+
71. Simplify Path.vcxproj
12+
This is the main project file for VC++ projects generated using an Application Wizard.
13+
It contains information about the version of Visual C++ that generated the file, and
14+
information about the platforms, configurations, and project features selected with the
15+
Application Wizard.
16+
17+
71. Simplify Path.vcxproj.filters
18+
This is the filters file for VC++ projects generated using an Application Wizard.
19+
It contains information about the association between the files in your project
20+
and the filters. This association is used in the IDE to show grouping of files with
21+
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
22+
"Source Files" filter).
23+
24+
71. Simplify Path.cpp
25+
This is the main application source file.
26+
27+
/////////////////////////////////////////////////////////////////////////////
28+
Other standard files:
29+
30+
StdAfx.h, StdAfx.cpp
31+
These files are used to build a precompiled header (PCH) file
32+
named 71. Simplify Path.pch and a precompiled types file named StdAfx.obj.
33+
34+
/////////////////////////////////////////////////////////////////////////////
35+
Other notes:
36+
37+
AppWizard uses "TODO:" comments to indicate parts of the source code you
38+
should add to or customize.
39+
40+
/////////////////////////////////////////////////////////////////////////////

leetcode/71. Simplify Path/stdafx.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// stdafx.cpp : source file that includes just the standard includes
2+
// 71. Simplify Path.pch will be the pre-compiled header
3+
// stdafx.obj will contain the pre-compiled type information
4+
5+
#include "stdafx.h"
6+
7+
// TODO: reference any additional headers you need in STDAFX.H
8+
// and not in this file

leetcode/71. Simplify Path/stdafx.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// stdafx.h : include file for standard system include files,
2+
// or project specific include files that are used frequently, but
3+
// are changed infrequently
4+
//
5+
6+
#pragma once
7+
8+
#include "targetver.h"
9+
10+
#include <stdio.h>
11+
#include <tchar.h>
12+
13+
14+
15+
// TODO: reference additional headers your program requires here
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
// Including SDKDDKVer.h defines the highest available Windows platform.
4+
5+
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
6+
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
7+
8+
#include <SDKDDKVer.h>

leetcode/leetcode.sdf

0 Bytes
Binary file not shown.

leetcode/leetcode.sln

+6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "47. Permutations II", "47.
8383
EndProject
8484
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "79. Word Search", "79. Word Search\79. Word Search.vcxproj", "{DFE8A26B-2B99-4EBF-B08A-4AEDB40943B9}"
8585
EndProject
86+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "71. Simplify Path", "71. Simplify Path\71. Simplify Path.vcxproj", "{56D11F29-656C-40F2-8B15-B06AA4DE7B0B}"
87+
EndProject
8688
Global
8789
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8890
Debug|Win32 = Debug|Win32
@@ -249,6 +251,10 @@ Global
249251
{DFE8A26B-2B99-4EBF-B08A-4AEDB40943B9}.Debug|Win32.Build.0 = Debug|Win32
250252
{DFE8A26B-2B99-4EBF-B08A-4AEDB40943B9}.Release|Win32.ActiveCfg = Release|Win32
251253
{DFE8A26B-2B99-4EBF-B08A-4AEDB40943B9}.Release|Win32.Build.0 = Release|Win32
254+
{56D11F29-656C-40F2-8B15-B06AA4DE7B0B}.Debug|Win32.ActiveCfg = Debug|Win32
255+
{56D11F29-656C-40F2-8B15-B06AA4DE7B0B}.Debug|Win32.Build.0 = Debug|Win32
256+
{56D11F29-656C-40F2-8B15-B06AA4DE7B0B}.Release|Win32.ActiveCfg = Release|Win32
257+
{56D11F29-656C-40F2-8B15-B06AA4DE7B0B}.Release|Win32.Build.0 = Release|Win32
252258
EndGlobalSection
253259
GlobalSection(SolutionProperties) = preSolution
254260
HideSolutionNode = FALSE

leetcode/leetcode.v12.suo

5.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)