mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-03-25 14:23:03 +08:00
Documentation for 8b1eab204b
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
<!-- HTML header for doxygen 1.12.0-->
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
|
||||
<head>
|
||||
@@ -5,10 +6,15 @@
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
||||
<meta name="generator" content="Doxygen 1.12.0"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<title>Algorithms_in_C++: others/longest_substring_without_repeating_characters.cpp File Reference</title>
|
||||
<title>TheAlgorithms/C++: others/longest_substring_without_repeating_characters.cpp File Reference</title>
|
||||
<link rel="icon" href="../../favicon.svg" type="image/x-icon" />
|
||||
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="../../jquery.js"></script>
|
||||
<script type="text/javascript" src="../../dynsections.js"></script>
|
||||
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@xpack-3rd-party/doxygen-awesome-css@2.2.0-1/doxygen-awesome-darkmode-toggle.js"></script>
|
||||
<script type="text/javascript">
|
||||
DoxygenAwesomeDarkModeToggle.init()
|
||||
</script>
|
||||
<script type="text/javascript" src="../../clipboard.js"></script>
|
||||
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="../../navtreedata.js"></script>
|
||||
@@ -18,14 +24,24 @@
|
||||
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="../../search/searchdata.js"></script>
|
||||
<script type="text/javascript" src="../../search/search.js"></script>
|
||||
<script type="text/x-mathjax-config">
|
||||
MathJax.Hub.Config({
|
||||
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
|
||||
jax: ["input/TeX","output/HTML-CSS"],
|
||||
});
|
||||
<script type="text/javascript">
|
||||
window.MathJax = {
|
||||
options: {
|
||||
ignoreHtmlClass: 'tex2jax_ignore',
|
||||
processHtmlClass: 'tex2jax_process'
|
||||
},
|
||||
loader: {
|
||||
load: ['[tex]/ams']
|
||||
},
|
||||
tex: {
|
||||
macros: {},
|
||||
packages: ['base','configmacros','ams']
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
|
||||
<script type="text/javascript" id="MathJax-script" async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
|
||||
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
|
||||
<link href="../../doxygen-awesome.css" rel="stylesheet" type="text/css"/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
||||
@@ -33,10 +49,11 @@ MathJax.Hub.Config({
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
<tbody>
|
||||
<tr id="projectrow">
|
||||
<td id="projectlogo"><img alt="Logo" src="../../project_logo.png"/></td>
|
||||
<td id="projectalign">
|
||||
<div id="projectname">Algorithms_in_C++<span id="projectnumber"> 1.0.0</span>
|
||||
<div id="projectname">TheAlgorithms/C++<span id="projectnumber"> 1.0.0</span>
|
||||
</div>
|
||||
<div id="projectbrief">Set of algorithms implemented in C++.</div>
|
||||
<div id="projectbrief">All the algorithms implemented in C++</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -123,7 +140,9 @@ Include dependency graph for longest_substring_without_repeating_characters.cpp:
|
||||
<div class="dyncontent">
|
||||
<div class="center"><iframe scrolling="no" frameborder="0" src="../../db/de5/longest__substring__without__repeating__characters_8cpp__incl.svg" width="463" height="126"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
|
||||
</div>
|
||||
</div><table class="memberdecls">
|
||||
</div>
|
||||
<p><a href="../../d4/db8/longest__substring__without__repeating__characters_8cpp_source.html">Go to the source code of this file.</a></p>
|
||||
<table class="memberdecls">
|
||||
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="nested-classes" name="nested-classes"></a>
|
||||
Classes</h2></td></tr>
|
||||
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">class  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../da/d21/class_longest___substring.html">Longest_Substring</a></td></tr>
|
||||
@@ -146,6 +165,8 @@ Functions</h2></td></tr>
|
||||
<p>Approach: 1) Initialize an unordered_map to track the frequency of characters. 2) Use a deque for pushing characters, and update the result deque (<code>res</code>) with the current deque (<code>temp</code>) whenever we find a longer substring. 3) Use a while loop to reduce the frequency from the front, incrementing <code>i</code>, and removing characters from the <code>temp</code> deque as we no longer need them. 4) Return <code>res.size()</code> as we are interested in the length of the longest substring.</p>
|
||||
<p>Time Complexity: O(N) Space Complexity: O(N)</p>
|
||||
<p>I hope this helps to understand. Thank you! </p><dl class="section author"><dt>Author</dt><dd><a href="../../github.com/ashish5kmax" target="_blank">Ashish Kumar Sahoo</a> </dd></dl>
|
||||
|
||||
<p class="definition">Definition in file <a class="el" href="../../d4/db8/longest__substring__without__repeating__characters_8cpp_source.html">longest_substring_without_repeating_characters.cpp</a>.</p>
|
||||
</div><h2 class="groupheader">Function Documentation</h2>
|
||||
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
|
||||
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">◆ </a></span>main()</h2>
|
||||
@@ -164,17 +185,14 @@ Functions</h2></td></tr>
|
||||
|
||||
<p>Main function. </p>
|
||||
<dl class="section return"><dt>Returns</dt><dd>0 on successful execution. </dd></dl>
|
||||
|
||||
<p class="definition">Definition at line <a class="el" href="../../d4/db8/longest__substring__without__repeating__characters_8cpp_source.html#l00107">107</a> of file <a class="el" href="../../d4/db8/longest__substring__without__repeating__characters_8cpp_source.html">longest_substring_without_repeating_characters.cpp</a>.</p>
|
||||
<div class="fragment"><div class="line"><span class="lineno"> 107</span> {</div>
|
||||
<div class="line"><span class="lineno"> 108</span> <a class="code hl_function" href="#a483bb8ccf42aaf7375a83e91490eda1e">tests</a>(); <span class="comment">// run self-test implementations</span></div>
|
||||
<div class="line"><span class="lineno"> 109</span> <span class="keywordflow">return</span> 0;</div>
|
||||
<div class="line"><span class="lineno"> 110</span>}</div>
|
||||
<div class="ttc" id="alongest__substring__without__repeating__characters_8cpp_html_a483bb8ccf42aaf7375a83e91490eda1e"><div class="ttname"><a href="#a483bb8ccf42aaf7375a83e91490eda1e">tests</a></div><div class="ttdeci">static void tests()</div><div class="ttdoc">Self-test implementations.</div><div class="ttdef"><b>Definition</b> longest_substring_without_repeating_characters.cpp:92</div></div>
|
||||
</div><!-- fragment --><div class="dynheader">
|
||||
Here is the call graph for this function:</div>
|
||||
<div class="dyncontent">
|
||||
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d4/db8/longest__substring__without__repeating__characters_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="579" height="192"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
|
||||
</div>
|
||||
|
||||
<div class="ttc" id="alongest__substring__without__repeating__characters_8cpp_html_a483bb8ccf42aaf7375a83e91490eda1e"><div class="ttname"><a href="#a483bb8ccf42aaf7375a83e91490eda1e">tests</a></div><div class="ttdeci">static void tests()</div><div class="ttdoc">Self-test implementations.</div><div class="ttdef"><b>Definition</b> <a href="../../d4/db8/longest__substring__without__repeating__characters_8cpp_source.html#l00092">longest_substring_without_repeating_characters.cpp:92</a></div></div>
|
||||
</div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
<a id="a483bb8ccf42aaf7375a83e91490eda1e" name="a483bb8ccf42aaf7375a83e91490eda1e"></a>
|
||||
@@ -202,6 +220,8 @@ Here is the call graph for this function:</div>
|
||||
|
||||
<p>Self-test implementations. </p>
|
||||
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
|
||||
|
||||
<p class="definition">Definition at line <a class="el" href="../../d4/db8/longest__substring__without__repeating__characters_8cpp_source.html#l00092">92</a> of file <a class="el" href="../../d4/db8/longest__substring__without__repeating__characters_8cpp_source.html">longest_substring_without_repeating_characters.cpp</a>.</p>
|
||||
<div class="fragment"><div class="line"><span class="lineno"> 92</span> {</div>
|
||||
<div class="line"><span class="lineno"> 93</span> <a class="code hl_class" href="../../da/d21/class_longest___substring.html">Longest_Substring</a> soln;</div>
|
||||
<div class="line"><span class="lineno"> 94</span> assert(soln.<a class="code hl_function" href="../../da/d21/class_longest___substring.html#af8a3672bc8d95e7da4f9a45e5e2e387d">lengthOfLongestSubstring</a>(<span class="stringliteral">"abcabcbb"</span>) == 3);</div>
|
||||
@@ -210,18 +230,11 @@ Here is the call graph for this function:</div>
|
||||
<div class="line"><span class="lineno"> 97</span> assert(soln.<a class="code hl_function" href="../../da/d21/class_longest___substring.html#af8a3672bc8d95e7da4f9a45e5e2e387d">lengthOfLongestSubstring</a>(<span class="stringliteral">""</span>) == 0); <span class="comment">// Test case for empty string</span></div>
|
||||
<div class="line"><span class="lineno"> 98</span> assert(soln.<a class="code hl_function" href="../../da/d21/class_longest___substring.html#af8a3672bc8d95e7da4f9a45e5e2e387d">lengthOfLongestSubstring</a>(<span class="stringliteral">"abcdef"</span>) == 6); <span class="comment">// Test case for all unique characters</span></div>
|
||||
<div class="line"><span class="lineno"> 99</span> assert(soln.<a class="code hl_function" href="../../da/d21/class_longest___substring.html#af8a3672bc8d95e7da4f9a45e5e2e387d">lengthOfLongestSubstring</a>(<span class="stringliteral">"a"</span>) == 1); <span class="comment">// Single character</span></div>
|
||||
<div class="line"><span class="lineno"> 100</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a> << <span class="stringliteral">"All test cases passed!"</span> << <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a>;</div>
|
||||
<div class="line"><span class="lineno"> 100</span> std::cout << <span class="stringliteral">"All test cases passed!"</span> << std::endl;</div>
|
||||
<div class="line"><span class="lineno"> 101</span>}</div>
|
||||
<div class="ttc" id="abasic_ostream_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/basic_ostream.html">std::cout</a></div></div>
|
||||
<div class="ttc" id="aclass_longest___substring_html"><div class="ttname"><a href="../../da/d21/class_longest___substring.html">Longest_Substring</a></div><div class="ttdoc">Class that solves the Longest Substring Without Repeating Characters problem.</div><div class="ttdef"><b>Definition</b> longest_substring_without_repeating_characters.cpp:37</div></div>
|
||||
<div class="ttc" id="aclass_longest___substring_html_af8a3672bc8d95e7da4f9a45e5e2e387d"><div class="ttname"><a href="../../da/d21/class_longest___substring.html#af8a3672bc8d95e7da4f9a45e5e2e387d">Longest_Substring::lengthOfLongestSubstring</a></div><div class="ttdeci">int lengthOfLongestSubstring(std::string s)</div><div class="ttdoc">Function to find the length of the longest substring without repeating characters.</div><div class="ttdef"><b>Definition</b> longest_substring_without_repeating_characters.cpp:44</div></div>
|
||||
<div class="ttc" id="aendl_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/io/manip/endl.html">std::endl</a></div><div class="ttdeci">T endl(T... args)</div></div>
|
||||
</div><!-- fragment --><div class="dynheader">
|
||||
Here is the call graph for this function:</div>
|
||||
<div class="dyncontent">
|
||||
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d4/db8/longest__substring__without__repeating__characters_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.svg" width="482" height="192"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
|
||||
</div>
|
||||
|
||||
<div class="ttc" id="aclass_longest___substring_html"><div class="ttname"><a href="../../da/d21/class_longest___substring.html">Longest_Substring</a></div><div class="ttdoc">Class that solves the Longest Substring Without Repeating Characters problem.</div><div class="ttdef"><b>Definition</b> <a href="../../d4/db8/longest__substring__without__repeating__characters_8cpp_source.html#l00037">longest_substring_without_repeating_characters.cpp:37</a></div></div>
|
||||
<div class="ttc" id="aclass_longest___substring_html_af8a3672bc8d95e7da4f9a45e5e2e387d"><div class="ttname"><a href="../../da/d21/class_longest___substring.html#af8a3672bc8d95e7da4f9a45e5e2e387d">Longest_Substring::lengthOfLongestSubstring</a></div><div class="ttdeci">int lengthOfLongestSubstring(std::string s)</div><div class="ttdoc">Function to find the length of the longest substring without repeating characters.</div><div class="ttdef"><b>Definition</b> <a href="../../d4/db8/longest__substring__without__repeating__characters_8cpp_source.html#l00044">longest_substring_without_repeating_characters.cpp:44</a></div></div>
|
||||
</div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- contents -->
|
||||
|
||||
Reference in New Issue
Block a user