-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatom.xml
More file actions
117 lines (93 loc) · 9.07 KB
/
Copy pathatom.xml
File metadata and controls
117 lines (93 loc) · 9.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Hi JsOoO</title>
<link href="/atom.xml" rel="self"/>
<link href="https://jsooo.github.io/"/>
<updated>2017-10-30T13:48:30.965Z</updated>
<id>https://jsooo.github.io/</id>
<author>
<name>Johnson Wang</name>
</author>
<generator uri="http://hexo.io/">Hexo</generator>
<entry>
<title>Longest Substring Without Repeating Characters</title>
<link href="https://jsooo.github.io/2017/10/30/longest-substring/"/>
<id>https://jsooo.github.io/2017/10/30/longest-substring/</id>
<published>2017-10-30T12:57:46.000Z</published>
<updated>2017-10-30T13:48:30.965Z</updated>
<content type="html"><![CDATA[<h3 id="0x00-题目"><a href="#0x00-题目" class="headerlink" title="0x00 题目"></a>0x00 题目</h3><p>Given a string, find the length of the longest substring without repeating characters.</p>
<p>Examples:</p>
<p>Given “abcabcbb”, the answer is “abc”, which the length is 3.</p>
<p>Given “bbbbb”, the answer is “b”, with the length of 1.</p>
<p>Given “pwwkew”, the answer is “wke”, with the length of 3. Note that the answer must be a substring, “pwke” is a subsequence and not a substring.</p>
<h3 id="0x01-分析"><a href="#0x01-分析" class="headerlink" title="0x01 分析"></a>0x01 分析</h3><p>目的是想要截取到给定字符串中最长的不重复的字符串。</p>
<p>eg:<br>abcabcabc => abc</p>
<p>aaaaaaaababcd => abcd</p>
<p>aaaaaa => a</p>
<h3 id="0x02-编码"><a href="#0x02-编码" class="headerlink" title="0x02 编码"></a>0x02 编码</h3><ul>
<li>golang 版本<figure class="highlight golang"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">func</span> <span class="title">lengthOfLongestSubstring</span><span class="params">(s <span class="keyword">string</span>)</span> <span class="title">int</span></span> {</div><div class="line"> location := <span class="built_in">make</span>([]<span class="keyword">int</span>, <span class="number">128</span>)</div><div class="line"></div><div class="line"> <span class="keyword">for</span> i := <span class="number">0</span>; i < <span class="number">128</span>; i++ {</div><div class="line"> location[i] = <span class="number">-1</span></div><div class="line"> }</div><div class="line"> begin, length := <span class="number">-1</span>, <span class="number">0</span></div><div class="line"> <span class="keyword">for</span> i, v := <span class="keyword">range</span> s {</div><div class="line"> <span class="keyword">if</span> location[v] > begin{</div><div class="line"> begin = location[s[i]]</div><div class="line"> }</div><div class="line"> <span class="keyword">if</span> (i - begin > length) {</div><div class="line"> length = i - begin;</div><div class="line"> }</div><div class="line"></div><div class="line"> location[s[i]] = i;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keyword">return</span> length</div><div class="line">}</div></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="0x03-运行结果"><a href="#0x03-运行结果" class="headerlink" title="0x03 运行结果"></a>0x03 运行结果</h3><table>
<thead>
<tr>
<th style="text-align:center">语言</th>
<th style="text-align:center">运行时间</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">Golang</td>
<td style="text-align:center">9ms</td>
</tr>
</tbody>
</table>
<p><a href="https://leetcode.com/problems/longest-substring-without-repeating-characters/description/" target="_blank" rel="external">传送门:Longest Substring Without Repeating Characters</a></p>
]]></content>
<summary type="html">
<h3 id="0x00-题目"><a href="#0x00-题目" class="headerlink" title="0x00 题目"></a>0x00 题目</h3><p>Given a string, find the length of the longest sub
</summary>
<category term="code" scheme="https://jsooo.github.io/categories/code/"/>
<category term="LeetCode" scheme="https://jsooo.github.io/tags/LeetCode/"/>
</entry>
<entry>
<title>Plus One</title>
<link href="https://jsooo.github.io/2017/08/05/plus-one/"/>
<id>https://jsooo.github.io/2017/08/05/plus-one/</id>
<published>2017-08-05T12:15:21.000Z</published>
<updated>2017-10-30T13:48:30.966Z</updated>
<content type="html"><![CDATA[<blockquote>
<p>时隔一年,重新写起博客,以前的东西没有存,随它去吧,重新开始。<br>去年年初接触到 <a href="https://leetcode.com" target="_blank" rel="external">LeetCode</a>,这是一个Online Judge网站,很有趣,从这篇博客开始,争取把所有题目都做完。</p>
</blockquote>
<h3 id="0x00-题目"><a href="#0x00-题目" class="headerlink" title="0x00 题目"></a>0x00 题目</h3><p>Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.</p>
<p>You may assume the integer do not contain any leading zero, except the number 0 itself.</p>
<p>The digits are stored such that the most significant digit is at the head of the list.</p>
<h3 id="0x01-分析"><a href="#0x01-分析" class="headerlink" title="0x01 分析"></a>0x01 分析</h3><p>根据字面意思简单的理解就是给一个正整数组成的数组,期望将数组中的数字看成一个整型数,对其进行加一操作。<br>eg:<br>[1] => [2]<br>[9] => [1, 0]<br>[1, 9, 9] => [2, 0, 0]</p>
<h3 id="0x02-编码"><a href="#0x02-编码" class="headerlink" title="0x02 编码"></a>0x02 编码</h3><ul>
<li>python 版本<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">Solution</span><span class="params">(object)</span>:</span></div><div class="line"> <span class="function"><span class="keyword">def</span> <span class="title">plusOne</span><span class="params">(self, digits)</span>:</span></div><div class="line"> <span class="keyword">if</span> len(digits) == <span class="number">0</span>: </div><div class="line"> <span class="keyword">return</span> digits</div><div class="line"> <span class="keyword">if</span> digits[<span class="number">0</span>] == <span class="number">9</span> <span class="keyword">and</span> len(digits) == <span class="number">1</span>:</div><div class="line"> <span class="keyword">return</span> [<span class="number">1</span>,<span class="number">0</span>]</div><div class="line"> <span class="keyword">if</span> digits[<span class="number">-1</span>] != <span class="number">9</span>:</div><div class="line"> digits[<span class="number">-1</span>] += <span class="number">1</span></div><div class="line"> <span class="keyword">return</span> digits</div><div class="line"> tmp = self.plusOne(digits[<span class="number">0</span>:<span class="number">-1</span>])</div><div class="line"> tmp.append(<span class="number">0</span>)</div><div class="line"> <span class="keyword">return</span> tmp</div></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="0x03-运行结果"><a href="#0x03-运行结果" class="headerlink" title="0x03 运行结果"></a>0x03 运行结果</h3><table>
<thead>
<tr>
<th style="text-align:center">语言</th>
<th style="text-align:center">运行时间</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">Python</td>
<td style="text-align:center">56ms</td>
</tr>
</tbody>
</table>
<p><a href="https://leetcode.com/problems/plus-one/description/" target="_blank" rel="external">传送门:Plus One</a></p>
]]></content>
<summary type="html">
<blockquote>
<p>时隔一年,重新写起博客,以前的东西没有存,随它去吧,重新开始。<br>去年年初接触到 <a href="https://leetcode.com" target="_blank" rel="external">LeetCode</a>,这是一个On
</summary>
<category term="code" scheme="https://jsooo.github.io/categories/code/"/>
<category term="LeetCode" scheme="https://jsooo.github.io/tags/LeetCode/"/>
</entry>
</feed>