mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-03-30 16:51:57 +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++: Longest_Substring Class Reference</title>
|
||||
<title>TheAlgorithms/C++: Longest_Substring Class 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>
|
||||
@@ -116,12 +133,14 @@ $(function(){initNavTree('da/d21/class_longest___substring.html','../../'); init
|
||||
<table class="memberdecls">
|
||||
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-methods" name="pub-methods"></a>
|
||||
Public Member Functions</h2></td></tr>
|
||||
<tr class="memitem:af8a3672bc8d95e7da4f9a45e5e2e387d" id="r_af8a3672bc8d95e7da4f9a45e5e2e387d"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="#af8a3672bc8d95e7da4f9a45e5e2e387d">lengthOfLongestSubstring</a> (<a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a> s)</td></tr>
|
||||
<tr class="memitem:af8a3672bc8d95e7da4f9a45e5e2e387d" id="r_af8a3672bc8d95e7da4f9a45e5e2e387d"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="#af8a3672bc8d95e7da4f9a45e5e2e387d">lengthOfLongestSubstring</a> (std::string s)</td></tr>
|
||||
<tr class="memdesc:af8a3672bc8d95e7da4f9a45e5e2e387d"><td class="mdescLeft"> </td><td class="mdescRight">Function to find the length of the longest substring without repeating characters. <br /></td></tr>
|
||||
<tr class="separator:af8a3672bc8d95e7da4f9a45e5e2e387d"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
</table>
|
||||
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
||||
<div class="textblock"><p>Class that solves the Longest Substring Without Repeating Characters problem. </p>
|
||||
|
||||
<p class="definition">Definition at line <a class="el" href="../../d4/db8/longest__substring__without__repeating__characters_8cpp_source.html#l00037">37</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><h2 class="groupheader">Member Function Documentation</h2>
|
||||
<a id="af8a3672bc8d95e7da4f9a45e5e2e387d" name="af8a3672bc8d95e7da4f9a45e5e2e387d"></a>
|
||||
<h2 class="memtitle"><span class="permalink"><a href="#af8a3672bc8d95e7da4f9a45e5e2e387d">◆ </a></span>lengthOfLongestSubstring()</h2>
|
||||
@@ -135,7 +154,7 @@ Public Member Functions</h2></td></tr>
|
||||
<tr>
|
||||
<td class="memname">int Longest_Substring::lengthOfLongestSubstring </td>
|
||||
<td>(</td>
|
||||
<td class="paramtype"><a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string.html">std::string</a></td> <td class="paramname"><span class="paramname"><em>s</em></span></td><td>)</td>
|
||||
<td class="paramtype">std::string</td> <td class="paramname"><span class="paramname"><em>s</em></span></td><td>)</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -154,17 +173,19 @@ Public Member Functions</h2></td></tr>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="section return"><dt>Returns</dt><dd>Length of the longest substring. </dd></dl>
|
||||
|
||||
<p class="definition">Definition at line <a class="el" href="../../d4/db8/longest__substring__without__repeating__characters_8cpp_source.html#l00044">44</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"> 44</span> {</div>
|
||||
<div class="line"><span class="lineno"> 45</span> <span class="comment">// If the size of string is 1, then it will be the answer.</span></div>
|
||||
<div class="line"><span class="lineno"> 46</span> <span class="keywordflow">if</span> (s.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">size</a>() == 1) <span class="keywordflow">return</span> 1;</div>
|
||||
<div class="line"><span class="lineno"> 46</span> <span class="keywordflow">if</span> (s.size() == 1) <span class="keywordflow">return</span> 1;</div>
|
||||
<div class="line"><span class="lineno"> 47</span> </div>
|
||||
<div class="line"><span class="lineno"> 48</span> <span class="comment">// Map used to store the character frequency.</span></div>
|
||||
<div class="line"><span class="lineno"> 49</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/unordered_map.html">std::unordered_map<char, int></a> m;</div>
|
||||
<div class="line"><span class="lineno"> 50</span> <span class="keywordtype">int</span> n = s.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">length</a>();</div>
|
||||
<div class="line"><span class="lineno"> 49</span> std::unordered_map<char, int> m;</div>
|
||||
<div class="line"><span class="lineno"> 50</span> <span class="keywordtype">int</span> n = s.length();</div>
|
||||
<div class="line"><span class="lineno"> 51</span> </div>
|
||||
<div class="line"><span class="lineno"> 52</span> <span class="comment">// Deque to remove from back if repeating characters are present.</span></div>
|
||||
<div class="line"><span class="lineno"> 53</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/deque.html">std::deque<char></a> temp;</div>
|
||||
<div class="line"><span class="lineno"> 54</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/deque.html">std::deque<char></a> res;</div>
|
||||
<div class="line"><span class="lineno"> 53</span> std::deque<char> temp;</div>
|
||||
<div class="line"><span class="lineno"> 54</span> std::deque<char> res;</div>
|
||||
<div class="line"><span class="lineno"> 55</span> <span class="keywordtype">int</span> i, j;</div>
|
||||
<div class="line"><span class="lineno"> 56</span> </div>
|
||||
<div class="line"><span class="lineno"> 57</span> <span class="comment">// Sliding window approach using two pointers.</span></div>
|
||||
@@ -173,44 +194,34 @@ Public Member Functions</h2></td></tr>
|
||||
<div class="line"><span class="lineno"> 60</span> </div>
|
||||
<div class="line"><span class="lineno"> 61</span> <span class="comment">// If repeating character found, update result and remove from the front.</span></div>
|
||||
<div class="line"><span class="lineno"> 62</span> <span class="keywordflow">if</span> (m[s[j]] > 1) {</div>
|
||||
<div class="line"><span class="lineno"> 63</span> <span class="keywordflow">if</span> (temp.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/deque/size.html">size</a>() > res.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/deque/size.html">size</a>()) {</div>
|
||||
<div class="line"><span class="lineno"> 63</span> <span class="keywordflow">if</span> (temp.size() > res.size()) {</div>
|
||||
<div class="line"><span class="lineno"> 64</span> res = temp;</div>
|
||||
<div class="line"><span class="lineno"> 65</span> }</div>
|
||||
<div class="line"><span class="lineno"> 66</span> </div>
|
||||
<div class="line"><span class="lineno"> 67</span> <span class="keywordflow">while</span> (m[s[j]] > 1) {</div>
|
||||
<div class="line"><span class="lineno"> 68</span> temp.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/deque/pop_front.html">pop_front</a>();</div>
|
||||
<div class="line"><span class="lineno"> 68</span> temp.pop_front();</div>
|
||||
<div class="line"><span class="lineno"> 69</span> m[s[i]]--;</div>
|
||||
<div class="line"><span class="lineno"> 70</span> i++;</div>
|
||||
<div class="line"><span class="lineno"> 71</span> }</div>
|
||||
<div class="line"><span class="lineno"> 72</span> }</div>
|
||||
<div class="line"><span class="lineno"> 73</span> </div>
|
||||
<div class="line"><span class="lineno"> 74</span> <span class="comment">// Add the current character to the deque.</span></div>
|
||||
<div class="line"><span class="lineno"> 75</span> temp.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/deque/push_back.html">push_back</a>(s[j]);</div>
|
||||
<div class="line"><span class="lineno"> 75</span> temp.push_back(s[j]);</div>
|
||||
<div class="line"><span class="lineno"> 76</span> j++;</div>
|
||||
<div class="line"><span class="lineno"> 77</span> }</div>
|
||||
<div class="line"><span class="lineno"> 78</span> </div>
|
||||
<div class="line"><span class="lineno"> 79</span> <span class="comment">// Final check to update result.</span></div>
|
||||
<div class="line"><span class="lineno"> 80</span> <span class="keywordflow">if</span> (temp.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/deque/size.html">size</a>() > res.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/deque/size.html">size</a>()) {</div>
|
||||
<div class="line"><span class="lineno"> 80</span> <span class="keywordflow">if</span> (temp.size() > res.size()) {</div>
|
||||
<div class="line"><span class="lineno"> 81</span> res = temp;</div>
|
||||
<div class="line"><span class="lineno"> 82</span> }</div>
|
||||
<div class="line"><span class="lineno"> 83</span> </div>
|
||||
<div class="line"><span class="lineno"> 84</span> <span class="keywordflow">return</span> res.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/deque/size.html">size</a>(); <span class="comment">// Return the length of the longest substring.</span></div>
|
||||
<div class="line"><span class="lineno"> 84</span> <span class="keywordflow">return</span> res.size(); <span class="comment">// Return the length of the longest substring.</span></div>
|
||||
<div class="line"><span class="lineno"> 85</span> }</div>
|
||||
<div class="ttc" id="adeque_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/deque.html">std::deque</a></div></div>
|
||||
<div class="ttc" id="apop_front_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/deque/pop_front.html">std::deque::pop_front</a></div><div class="ttdeci">T pop_front(T... args)</div></div>
|
||||
<div class="ttc" id="apush_back_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/deque/push_back.html">std::deque::push_back</a></div><div class="ttdeci">T push_back(T... args)</div></div>
|
||||
<div class="ttc" id="asize_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/string/basic_string/size.html">std::string::size</a></div><div class="ttdeci">T size(T... args)</div></div>
|
||||
<div class="ttc" id="aunordered_map_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/unordered_map.html">std::unordered_map</a></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="../../da/d21/class_longest___substring_af8a3672bc8d95e7da4f9a45e5e2e387d_cgraph.svg" width="384" height="184"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
|
||||
</div>
|
||||
|
||||
</div><!-- fragment -->
|
||||
</div>
|
||||
</div>
|
||||
<hr/>The documentation for this class was generated from the following file:<ul>
|
||||
<li>others/<a class="el" href="../../d4/db8/longest__substring__without__repeating__characters_8cpp.html">longest_substring_without_repeating_characters.cpp</a></li>
|
||||
<li>others/<a class="el" href="../../d4/db8/longest__substring__without__repeating__characters_8cpp_source.html">longest_substring_without_repeating_characters.cpp</a></li>
|
||||
</ul>
|
||||
</div><!-- contents -->
|
||||
</div><!-- doc-content -->
|
||||
|
||||
Reference in New Issue
Block a user