-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatom.xml
571 lines (284 loc) · 103 KB
/
atom.xml
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>木木和他的朋友们</title>
<subtitle>YangLin's Blog</subtitle>
<link href="http://tiawnen42.top/atom.xml" rel="self"/>
<link href="http://tiawnen42.top/"/>
<updated>2022-07-07T00:14:06.000Z</updated>
<id>http://tiawnen42.top/</id>
<author>
<name>木木</name>
</author>
<generator uri="https://hexo.io/">Hexo</generator>
<entry>
<title>热爱生命</title>
<link href="http://tiawnen42.top/posts/fab5.html"/>
<id>http://tiawnen42.top/posts/fab5.html</id>
<published>2022-07-06T08:18:57.000Z</published>
<updated>2022-07-07T00:14:06.000Z</updated>
<content type="html"><![CDATA[<h1 id="《热爱生命》——汪国真"><a href="#《热爱生命》——汪国真" class="headerlink" title="《热爱生命》——汪国真"></a>《热爱生命》——汪国真</h1><blockquote><p>我不去想,<br>是否能够成功 ,<br>既然选择了远方 ,<br>便只顾风雨兼程。<br>我不去想,<br>能否赢得爱情 ,<br>既然钟情于玫瑰 ,<br>就勇敢地吐露真诚 。<br>我不去想,<br>身后会不会袭来寒风冷雨 ,<br>既然目标是地平线,<br>留给世界的只能是背影 。<br>我不去想,<br>未来是平坦还是泥泞 ,<br>只要热爱生命 ,<br>一切,都在意料之中。</p></blockquote>]]></content>
<summary type="html"><h1 id="《热爱生命》——汪国真"><a href="#《热爱生命》——汪国真" class="headerlink" title="《热爱生命》——汪国真"></a>《热爱生命》——汪国真</h1><blockquote>
<p>我不去想,<br>是否能够成功 ,<br></summary>
<category term="读书" scheme="http://tiawnen42.top/categories/%E8%AF%BB%E4%B9%A6/"/>
</entry>
<entry>
<title>力扣2022-04-19</title>
<link href="http://tiawnen42.top/posts/9c17.html"/>
<id>http://tiawnen42.top/posts/9c17.html</id>
<published>2022-04-19T14:43:23.000Z</published>
<updated>2022-04-28T13:54:30.000Z</updated>
<content type="html"><![CDATA[<h2 id="题目"><a href="#题目" class="headerlink" title="题目"></a>题目</h2><ol start="342"><li>4的幂</li></ol><p>难度:简单</p><p>给定一个整数,写一个函数来判断它是否是 4 的幂次方。如果是,返回 true ;否则,返回 false 。</p><p>整数 n 是 4 的幂次方需满足:存在整数 x 使得 n == 4<sup>x</sup></p><p><strong>示例 1:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:n = 16输出:true<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 2:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:n = 5输出:false<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 3:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:n = 1输出:true<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>提示:</strong></p><ul><li>-2<sup>31</sup> <= n <= 2<sup>31</sup> - 1</li></ul><p><strong>进阶:</strong>你能不使用循环或者递归来完成本题吗?</p><p>来源:力扣(LeetCode)<br>链接:<a href="https://leetcode-cn.com/problems/power-of-four/">https://leetcode-cn.com/problems/power-of-four/</a><br>著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。</p><h2 id="解题思路"><a href="#解题思路" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>4的n次幂模4 和 4的 n-k次幂模4 都为0</p></blockquote><h2 id="解题代码"><a href="#解题代码" class="headerlink" title="解题代码"></a>解题代码</h2><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">/* * @lc app=leetcode.cn id=342 lang=cpp * * [342] 4的幂 */// @lc code=startclass Solution {public: bool isPowerOfFour(int num) { return num>0 && (num == 1 ||(num%4==0 && isPowerOfFour(num/4))); }};// @lc code=end<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h2 id="题目"><a href="#题目" class="headerlink" title="题目"></a>题目</h2><ol start="342">
<li>4的幂</li>
</ol>
<p>难度:简单</p>
<p>给定一个整数,写一个函数来判断它是否是 4</summary>
<category term="数据结构与算法" scheme="http://tiawnen42.top/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://tiawnen42.top/tags/%E7%AE%97%E6%B3%95/"/>
<category term="leetcode" scheme="http://tiawnen42.top/tags/leetcode/"/>
</entry>
<entry>
<title>力扣2022-04-16</title>
<link href="http://tiawnen42.top/posts/9857.html"/>
<id>http://tiawnen42.top/posts/9857.html</id>
<published>2022-04-16T15:44:03.000Z</published>
<updated>2022-04-28T13:54:30.000Z</updated>
<content type="html"><![CDATA[<h2 id="题目-剑指-Offer-II-079-所有子集"><a href="#题目-剑指-Offer-II-079-所有子集" class="headerlink" title="题目.剑指 Offer II 079. 所有子集"></a>题目.剑指 Offer II 079. 所有子集</h2><p>难度:中等</p><p>给定一个整数数组 nums ,数组中的元素 <strong>互不相同</strong> 。返回该数组所有可能的子集(幂集)。</p><p>解集 <strong>不能</strong> 包含重复的子集。你可以按 <strong>任意顺序</strong> 返回解集。</p><p><strong>示例 1:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:nums = [1,2,3]输出:[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 2:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:nums = [0]输出:[[],[0]]<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>提示:</strong></p><ul><li>1 <= nums.length <= 10</li><li>-10 <= nums[i] <= 10</li><li>nums 中的所有元素 <strong>互不相同</strong></li></ul><p>注意:本题与主站 78 题相同: <a href="https://leetcode-cn.com/problems/subsets/">https://leetcode-cn.com/problems/subsets/</a></p><p>来源:力扣(LeetCode)<br>链接:<a href="https://leetcode-cn.com/problems/TVdhkn/">https://leetcode-cn.com/problems/TVdhkn/</a><br>著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。</p><h2 id="解题思路"><a href="#解题思路" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>可以正常遍历,也可以用dfs</p></blockquote><h2 id="解题代码"><a href="#解题代码" class="headerlink" title="解题代码"></a>解题代码</h2><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">class Solution {public: vector<vector<int>> subsets(vector<int>& nums) { vector<vector<int>> res{vector<int>()}; int i, j, len; for (i=0; i<nums.size(); i++) { len = res.size(); for (j=0; j<len; j++) { auto tmp = res[j]; tmp.push_back(nums[i]); res.push_back(tmp); } } return res; }};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h2 id="题目-剑指-Offer-II-079-所有子集"><a href="#题目-剑指-Offer-II-079-所有子集" class="headerlink" title="题目.剑指 Offer II 079. 所有子集"></a>题目.剑指 Offer II 0</summary>
<category term="数据结构与算法" scheme="http://tiawnen42.top/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://tiawnen42.top/tags/%E7%AE%97%E6%B3%95/"/>
<category term="leetcode" scheme="http://tiawnen42.top/tags/leetcode/"/>
<category term="剑指 Offer" scheme="http://tiawnen42.top/tags/%E5%89%91%E6%8C%87-Offer/"/>
</entry>
<entry>
<title>力扣2022-04-14</title>
<link href="http://tiawnen42.top/posts/59d6.html"/>
<id>http://tiawnen42.top/posts/59d6.html</id>
<published>2022-04-14T13:38:00.000Z</published>
<updated>2022-04-14T13:51:28.000Z</updated>
<content type="html"><![CDATA[<h2 id="题目22-括号生成"><a href="#题目22-括号生成" class="headerlink" title="题目22.括号生成"></a>题目22.括号生成</h2><p>难度:中等</p><p>数字 n 代表生成括号的对数,请你设计一个函数,用于能够生成所有可能的并且 **有效的 **括号组合。</p><p><strong>示例 1:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:n = 3输出:["((()))","(()())","(())()","()(())","()()()"]<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 2:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:n = 1输出:["()"]<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>提示:</strong></p><ul><li>1 <= n <= 8</li></ul><p>来源:力扣(LeetCode)<br>链接:<a href="https://leetcode-cn.com/problems/generate-parentheses/">https://leetcode-cn.com/problems/generate-parentheses/</a><br>著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。</p><h2 id="解题思路"><a href="#解题思路" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>dfs,左右子树为(),刚好对应二叉树结构</p></blockquote><h2 id="解题代码"><a href="#解题代码" class="headerlink" title="解题代码"></a>解题代码</h2><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">class Solution {public: vector<string> generateParenthesis(int n) { vector<string> res; if (n <= 0) return res; dfs(n, "", res, 0, 0); return res; } void dfs(int n, string path, vector<string>& res, int open, int close) { if (open > n || close > open) return; if (path.length() == 2 * n) { res.push_back(path); return; } dfs(n, path + "(", res, open + 1, close); dfs(n, path + ")", res, open, close + 1); }};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h2 id="题目22-括号生成"><a href="#题目22-括号生成" class="headerlink" title="题目22.括号生成"></a>题目22.括号生成</h2><p>难度:中等</p>
<p>数字 n 代表生成括号的对数,请你设计一个函数,用于能够生</summary>
<category term="数据结构与算法" scheme="http://tiawnen42.top/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://tiawnen42.top/tags/%E7%AE%97%E6%B3%95/"/>
<category term="leetcode" scheme="http://tiawnen42.top/tags/leetcode/"/>
</entry>
<entry>
<title>力扣2022-04-13</title>
<link href="http://tiawnen42.top/posts/9b97.html"/>
<id>http://tiawnen42.top/posts/9b97.html</id>
<published>2022-04-13T06:21:00.000Z</published>
<updated>2022-04-13T10:23:24.000Z</updated>
<content type="html"><![CDATA[<h2 id="题目35-搜索插入位置"><a href="#题目35-搜索插入位置" class="headerlink" title="题目35.搜索插入位置"></a>题目35.搜索插入位置</h2><p>难度:简单</p><p>给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。</p><p>请必须使用时间复杂度为 O(log n) 的算法。</p><p><strong>示例 1:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入: nums = [1,3,5,6], target = 5输出: 2<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 2:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入: nums = [1,3,5,6], target = 2输出: 1<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 3:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入: nums = [1,3,5,6], target = 7输出: 4<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>提示:</strong></p><ul><li>1 <= nums.length <= 10<sup>4</sup></li><li>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></li><li>nums 为 **无重复元素 **的 **升序 **排列数组</li><li>-10<sup>4</sup> <= target <= 10<sup>4</sup></li></ul><p>来源:力扣(LeetCode)<br>链接:<a href="https://leetcode-cn.com/problems/search-insert-position/">https://leetcode-cn.com/problems/search-insert-position/</a><br>著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。</p><h2 id="解题思路"><a href="#解题思路" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>简单二分,要求O(log n) ,尽量不要暴力搜索</p></blockquote><h2 id="解题代码"><a href="#解题代码" class="headerlink" title="解题代码"></a>解题代码</h2><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">class Solution {public: int searchInsert(vector<int>& nums, int target) { int left=0; int right=nums.size()-1; int mid=left+(right-left)/2; if(target>nums[right]){ return right+1; } while(left<right){ if(nums[mid]==target){ return mid; } if(nums[mid]<target){ left=mid+1; }else{ right=mid; } mid=left+(right-left)/2; } return mid; }};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h2 id="题目35-搜索插入位置"><a href="#题目35-搜索插入位置" class="headerlink" title="题目35.搜索插入位置"></a>题目35.搜索插入位置</h2><p>难度:简单</p>
<p>给定一个排序数组和一个目标值,在数组中找到</summary>
<category term="数据结构与算法" scheme="http://tiawnen42.top/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://tiawnen42.top/tags/%E7%AE%97%E6%B3%95/"/>
<category term="leetcode" scheme="http://tiawnen42.top/tags/leetcode/"/>
<category term="二分法" scheme="http://tiawnen42.top/tags/%E4%BA%8C%E5%88%86%E6%B3%95/"/>
</entry>
<entry>
<title>力扣2022-04-11</title>
<link href="http://tiawnen42.top/posts/5a16.html"/>
<id>http://tiawnen42.top/posts/5a16.html</id>
<published>2022-04-11T06:11:00.000Z</published>
<updated>2022-04-13T10:25:32.000Z</updated>
<content type="html"><![CDATA[<h2 id="题目42-接雨水"><a href="#题目42-接雨水" class="headerlink" title="题目42.接雨水"></a>题目42.接雨水</h2><p>难度:困难</p><p>给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水。</p><p><strong>示例 1:</strong></p><img style="height: 161px; width: 412px;" src="https://qiniu.tianwen42.top/picgo/rainwatertrap.png"><pre class="line-numbers language-none"><code class="language-none">输入:height = [0,1,0,2,1,0,1,3,2,1,2,1]输出:6解释:上面是由数组 [0,1,0,2,1,0,1,3,2,1,2,1] 表示的高度图,在这种情况下,可以接 6 个单位的雨水(蓝色部分表示雨水)。 <span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p><strong>示例 2:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:height = [4,2,0,3,2,5]输出:9<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>提示:</strong></p><ul><li>n == height.length</li><li>1 <= n <= 2 * 10<sup>4</sup></li><li>0 <= height[i] <= 10<sup>5</sup></li></ul><p>来源:力扣(LeetCode)<br>链接:<a href="https://leetcode-cn.com/problems/trapping-rain-water/">https://leetcode-cn.com/problems/trapping-rain-water/</a><br>著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。</p><h2 id="解题思路"><a href="#解题思路" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>日常接雨水,暴力搜索,脑子不够</p></blockquote><h2 id="解题代码"><a href="#解题代码" class="headerlink" title="解题代码"></a>解题代码</h2><h3 id="暴力搜索"><a href="#暴力搜索" class="headerlink" title="暴力搜索"></a>暴力搜索</h3><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">class Solution {public: int trap(vector<int>& nums) { int maxHeight=0; int rain=0; for(int i=0;i<nums.size();i++){ maxHeight=max(nums[i],maxHeight); } for(int i=0;i<nums.size();i++){ int maxleft=0,maxright=0; //左侧最大高度 for(int j=0;j<=i;j++){ maxleft=max(maxleft,nums[j]); } // 右侧最大高度 for(int j=i;j<nums.size();j++){ maxright=max(maxright,nums[j]); } //当前位置可接高度min(Maxleft,Maxright),取决于左右最大高度低值 rain+=min(maxright, maxleft)-nums[i];; } return rain; }};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><blockquote><p>超时了!!!×&%¥#@……。</p><p>果然日常接雨水啊!!!!!</p></blockquote><h3 id="DP法"><a href="#DP法" class="headerlink" title="DP法"></a>DP法</h3><blockquote><p>看看别人的,需要从两头重新遍历一遍求出左右两侧的最大高度,这里是有很多重复计算的,很明显最大高度是可以记忆化的,用两个数组分别存每个位置的左右最大高度,</p><p>int[][] dp = new int [n] [2],其中,dp [i] [0] 表示下标i的柱子左边的最大值,dp[i] [1] 表示下标i的柱子右边的最大值。</p><p>类比这题</p><ul><li><a href="https://tianwen42.top/posts/ea37.html">807.城市天际线</a></li></ul></blockquote><p>左右高度数组如下图所示</p><p><img src="https://qiniu.tianwen42.top/picgo/rain0421.jpg" alt="img"></p><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">class Solution {public:int trap(vector<int>& height) {int n = height.size();// left[i]表示i左边的最大值,right[i]表示i右边的最大值vector<int> left(n), right(n);for (int i = 1; i < n; i++) {left[i] = max(left[i - 1], height[i - 1]);}for (int i = n - 2; i >= 0; i--) {right[i] = max(right[i + 1], height[i + 1]);}int water = 0;for (int i = 0; i < n; i++) {int level = min(left[i], right[i]);water += max(0, level - height[i]);}return water;}};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h2 id="题目42-接雨水"><a href="#题目42-接雨水" class="headerlink" title="题目42.接雨水"></a>题目42.接雨水</h2><p>难度:困难</p>
<p>给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排</summary>
<category term="数据结构与算法" scheme="http://tiawnen42.top/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://tiawnen42.top/tags/%E7%AE%97%E6%B3%95/"/>
<category term="leetcode" scheme="http://tiawnen42.top/tags/leetcode/"/>
<category term="接雨水" scheme="http://tiawnen42.top/tags/%E6%8E%A5%E9%9B%A8%E6%B0%B4/"/>
</entry>
<entry>
<title>力扣2022-04-10-2</title>
<link href="http://tiawnen42.top/posts/7bb.html"/>
<id>http://tiawnen42.top/posts/7bb.html</id>
<published>2022-04-10T15:53:12.000Z</published>
<updated>2022-04-13T10:23:24.000Z</updated>
<content type="html"><![CDATA[<h2 id="题目852-山脉数组的峰顶索引"><a href="#题目852-山脉数组的峰顶索引" class="headerlink" title="题目852.山脉数组的峰顶索引"></a>题目852.山脉数组的峰顶索引</h2><p>难度:简单</p><p><strong>山脉数组</strong><code>arr</code></p><ul><li>arr.length >= 3</li><li>存在 i(0 < i < arr.length - 1)使得: <ul> <li>arr[0] < arr[1] < ... arr[i-1] < arr[i] </li> <li>arr[i] > arr[i+1] > ... > arr[arr.length - 1]</li> </ul></li></ul><p>给你由整数组成的山脉数组 arr ,返回任何满足 arr[0] < arr[1] < … arr[i - 1] < arr[i] > arr[i + 1] > … > arr[arr.length - 1] 的下标 i 。</p><p><strong>示例 1:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:arr = [0,1,0]输出:1<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 2:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:arr = [0,2,1,0]输出:1<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 3:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:arr = [0,10,5,2]输出:1<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 4:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:arr = [3,4,5,1]输出:2<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 5:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:arr = [24,69,100,99,79,78,67,36,26,19]输出:2<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>提示:</strong></p><ul><li>3 <= arr.length <= 10<sup>4</sup></li><li>0 <= arr[i] <= 10<sup>6</sup></li><li>题目数据保证 arr 是一个山脉数组</li></ul><p><strong>进阶:</strong>很容易想到时间复杂度 O(n) 的解决方案,你可以设计一个 O(log(n)) 的解决方案吗?</p><p>来源:力扣(LeetCode)<br>链接:<a href="https://leetcode-cn.com/problems/peak-index-in-a-mountain-array/">https://leetcode-cn.com/problems/peak-index-in-a-mountain-array/</a><br>著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。</p><h2 id="解题思路"><a href="#解题思路" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><ol><li>直接暴力法arr[i]>arr[i-1]&&arr[i]>arr[i+1]</li><li>二分法</li></ol><p>支持暴力法和二分法,显然二分法更快</p></blockquote><h2 id="解题代码"><a href="#解题代码" class="headerlink" title="解题代码"></a>解题代码</h2><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">//暴力法class Solution {public: int peakIndexInMountainArray(vector<int>& arr) { if(arr[0]>arr[1]){ return 0; } for(int i=1;i<arr.size()-1;i++){ if(arr[i]>arr[i-1]&&arr[i]>arr[i+1]){ return i; } } return arr.size()-1; }};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">class Solution {public: int peakIndexInMountainArray(vector<int>& arr) { // if(arr[0]>arr[1]){return 0;} int left=0,right=arr.size()-1,mid=left+(right-left)/2; while(left!=right){ if(arr[left]<arr[mid]){ right=mid; }else{ left=mid+1; } mid=left+(right-left)/2; } return left; }};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h2 id="题目852-山脉数组的峰顶索引"><a href="#题目852-山脉数组的峰顶索引" class="headerlink" title="题目852.山脉数组的峰顶索引"></a>题目852.山脉数组的峰顶索引</h2><p>难度:简单</p>
<p><stro</summary>
<category term="数据结构与算法" scheme="http://tiawnen42.top/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://tiawnen42.top/tags/%E7%AE%97%E6%B3%95/"/>
<category term="leetcode" scheme="http://tiawnen42.top/tags/leetcode/"/>
</entry>
<entry>
<title>力扣2022-04-10</title>
<link href="http://tiawnen42.top/posts/b877.html"/>
<id>http://tiawnen42.top/posts/b877.html</id>
<published>2022-04-10T15:40:48.000Z</published>
<updated>2022-04-13T10:23:24.000Z</updated>
<content type="html"><![CDATA[<h2 id="题目374-猜数字大小"><a href="#题目374-猜数字大小" class="headerlink" title="题目374.猜数字大小"></a>题目374.猜数字大小</h2><p>难度:简单</p><p>猜数字游戏的规则如下:</p><ul><li>每轮游戏,我都会从 <strong>1</strong> 到 <em><strong>n</strong></em> 随机选择一个数字。 请你猜选出的是哪个数字。</li><li>如果你猜错了,我会告诉你,你猜测的数字比我选出的数字是大了还是小了。</li></ul><p>你可以通过调用一个预先定义好的接口 int guess(int num) 来获取猜测结果,返回值一共有 3 种可能的情况(-1,1 或 0):</p><ul><li>-1:我选出的数字比你猜的数字小 pick < num</li><li>1:我选出的数字比你猜的数字大 pick > num</li><li>0:我选出的数字和你猜的数字一样。恭喜!你猜对了!pick == num</li></ul><p>返回我选出的数字。</p><p><strong>示例 1:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:n = 10, pick = 6输出:6<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 2:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:n = 1, pick = 1输出:1<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 3:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:n = 2, pick = 1输出:1<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 4:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:n = 2, pick = 2输出:2<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>提示:</strong></p><ul><li>1 <= n <= 2<sup>31</sup> - 1</li><li>1 <= pick <= n</li></ul><p>来源:力扣(LeetCode)<br>链接:<a href="https://leetcode-cn.com/problems/guess-number-higher-or-lower/">https://leetcode-cn.com/problems/guess-number-higher-or-lower/</a><br>著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。</p><h2 id="解题思路"><a href="#解题思路" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p><strong>二分核心</strong>,精髓,这样写防止越界,mid = left + ((right - left) / 2);</p><pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token keyword">while</span><span class="token punctuation">(</span>l<span class="token operator">!=</span>r<span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token keyword">int</span> mid <span class="token operator">=</span> l <span class="token operator">+</span><span class="token punctuation">(</span>r <span class="token operator">-</span> l<span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">2</span><span class="token punctuation">;</span> <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">guess</span><span class="token punctuation">(</span>mid<span class="token punctuation">)</span><span class="token operator">==</span><span class="token number">1</span><span class="token punctuation">)</span> l <span class="token operator">=</span> mid<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">;</span> <span class="token keyword">else</span> r <span class="token operator">=</span> mid<span class="token punctuation">;</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre></blockquote><h2 id="解题代码"><a href="#解题代码" class="headerlink" title="解题代码"></a>解题代码</h2><pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Solution</span> <span class="token keyword">extends</span> <span class="token class-name">GuessGame</span> <span class="token punctuation">{</span> <span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">guessNumber</span><span class="token punctuation">(</span><span class="token keyword">int</span> n<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">int</span> l <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">,</span> r <span class="token operator">=</span> n<span class="token punctuation">;</span> <span class="token keyword">while</span><span class="token punctuation">(</span>l<span class="token operator">!=</span>r<span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token keyword">int</span> mid <span class="token operator">=</span> l <span class="token operator">+</span><span class="token punctuation">(</span>r <span class="token operator">-</span> l<span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">2</span><span class="token punctuation">;</span> <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">guess</span><span class="token punctuation">(</span>mid<span class="token punctuation">)</span><span class="token operator">==</span><span class="token number">1</span><span class="token punctuation">)</span> l <span class="token operator">=</span> mid<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">;</span> <span class="token keyword">else</span> r <span class="token operator">=</span> mid<span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">return</span> l<span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h2 id="题目374-猜数字大小"><a href="#题目374-猜数字大小" class="headerlink" title="题目374.猜数字大小"></a>题目374.猜数字大小</h2><p>难度:简单</p>
<p>猜数字游戏的规则如下:</p>
<ul>
</summary>
<category term="数据结构与算法" scheme="http://tiawnen42.top/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://tiawnen42.top/tags/%E7%AE%97%E6%B3%95/"/>
<category term="leetcode" scheme="http://tiawnen42.top/tags/leetcode/"/>
<category term="二分查找" scheme="http://tiawnen42.top/tags/%E4%BA%8C%E5%88%86%E6%9F%A5%E6%89%BE/"/>
<category term="核心" scheme="http://tiawnen42.top/tags/%E6%A0%B8%E5%BF%83/"/>
</entry>
<entry>
<title>力扣2022-04-07</title>
<link href="http://tiawnen42.top/posts/ea37.html"/>
<id>http://tiawnen42.top/posts/ea37.html</id>
<published>2022-04-07T01:59:30.000Z</published>
<updated>2022-04-11T06:14:14.000Z</updated>
<content type="html"><![CDATA[<h2 id="题目2229-Check-if-an-Array-Is-Consecutive"><a href="#题目2229-Check-if-an-Array-Is-Consecutive" class="headerlink" title="题目2229.Check if an Array Is Consecutive"></a>题目2229.Check if an Array Is Consecutive</h2><p>难度:简单</p><p>Given an integer array nums, return true <em>if </em>nums<em> is <strong>consecutive</strong>, otherwise return </em>false<em>.</em></p><p>An array is **consecutive **if it contains every number in the range [x, x + n - 1] (<strong>inclusive</strong>), where x is the minimum number in the array and n is the length of the array.</p><p><strong>Example 1:</strong></p><pre class="line-numbers language-none"><code class="language-none">Input: nums = [1,3,4,2]Output: trueExplanation:The minimum value is 1 and the length of nums is 4.All of the values in the range [x, x + n - 1] = [1, 1 + 4 - 1] = [1, 4] = (1, 2, 3, 4) occur in nums.Therefore, nums is consecutive.<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p><strong>Example 2:</strong></p><pre class="line-numbers language-none"><code class="language-none">Input: nums = [1,3]Output: falseExplanation:The minimum value is 1 and the length of nums is 2.The value 2 in the range [x, x + n - 1] = [1, 1 + 2 - 1], = [1, 2] = (1, 2) does not occur in nums.Therefore, nums is not consecutive.<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p><strong>Example 3:</strong></p><pre class="line-numbers language-none"><code class="language-none">Input: nums = [3,5,4]Output: trueExplanation:The minimum value is 3 and the length of nums is 3.All of the values in the range [x, x + n - 1] = [3, 3 + 3 - 1] = [3, 5] = (3, 4, 5) occur in nums.Therefore, nums is consecutive.<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p><strong>Constraints:</strong></p><ul><li>1 <= nums.length <= 10<sup>5</sup></li><li>0 <= nums[i] <= 10<sup>5</sup></li></ul><p>来源:力扣(LeetCode)<br>链接:<a href="https://leetcode-cn.com/problems/check-if-an-array-is-consecutive/">https://leetcode-cn.com/problems/check-if-an-array-is-consecutive/</a><br>著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。</p><h2 id="解题思路"><a href="#解题思路" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>排序,新建a,判断是否在nums中<br>扩展思考: a所有元素(可能重复/不重复)是否在b中</p></blockquote><h2 id="解题代码"><a href="#解题代码" class="headerlink" title="解题代码"></a>解题代码</h2><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">class Solution{public: bool isConsecutive(vector<int> &nums) { // if(nums == nullptr) return; int n = nums.size(); // size sort(nums.begin(), nums.end()); int min = nums[0]; //最小值 vector<int> vec; for (int i = min; i <= n + min - 1; i++) { vec.push_back(i); } int i = 0; while (i < vec.size()) { if (vec[i] == nums[i]) i++; else return false; } return true; }};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h2 id="题目2229-Check-if-an-Array-Is-Consecutive"><a href="#题目2229-Check-if-an-Array-Is-Consecutive" class="headerlink" title="题目2229.Check i</summary>
<category term="数据结构与算法" scheme="http://tiawnen42.top/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://tiawnen42.top/tags/%E7%AE%97%E6%B3%95/"/>
<category term="leetcode" scheme="http://tiawnen42.top/tags/leetcode/"/>
</entry>
<entry>
<title>力扣2022-04-06</title>
<link href="http://tiawnen42.top/posts/ea37.html"/>
<id>http://tiawnen42.top/posts/ea37.html</id>
<published>2022-04-06T15:58:15.000Z</published>
<updated>2022-04-11T06:14:14.000Z</updated>
<content type="html"><![CDATA[<h2 id="题目807-保持城市天际线"><a href="#题目807-保持城市天际线" class="headerlink" title="题目807.保持城市天际线"></a>题目807.保持城市天际线</h2><p>难度:中等</p><p>给你一座由 n x n 个街区组成的城市,每个街区都包含一座立方体建筑。给你一个下标从 <strong>0</strong> 开始的 n x n 整数矩阵 grid ,其中 grid[r][c] 表示坐落于 r 行 c 列的建筑物的 <strong>高度</strong> 。</p><p>城市的 <strong>天际线</strong> 是从远处观察城市时,所有建筑物形成的外部轮廓。从东、南、西、北四个主要方向观测到的 <strong>天际线</strong> 可能不同。</p><p>我们被允许为 <strong>任意数量的建筑物 <strong>的高度增加</strong> 任意增量(不同建筑物的增量可能不同)</strong> 。 高度为 0 的建筑物的高度也可以增加。然而,增加的建筑物高度 <strong>不能影响</strong> 从任何主要方向观察城市得到的 <strong>天际线</strong> 。</p><p>在 <strong>不改变</strong> 从任何主要方向观测到的城市 <strong>天际线</strong> 的前提下,返回建筑物可以增加的 <strong>最大高度增量总和</strong> 。</p><p><strong>示例 1:</strong></p><img style="width: 700px; height: 603px;" src="https://qiniu.tianwen42.top/picgo/807-ex1.png" alt=""><pre class="line-numbers language-none"><code class="language-none">输入:grid = [[3,0,8,4],[2,4,5,7],[9,2,6,3],[0,3,1,0]]输出:35解释:建筑物的高度如上图中心所示。用红色绘制从不同方向观看得到的天际线。在不影响天际线的情况下,增加建筑物的高度:gridNew = [ [8, 4, 8, 7], [7, 4, 7, 7], [9, 4, 8, 7], [3, 3, 3, 3] ]<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p><strong>示例 2:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:grid = [[0,0,0],[0,0,0],[0,0,0]]输出:0解释:增加任何建筑物的高度都会导致天际线的变化。<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p><strong>提示:</strong></p><ul><li>n == grid.length</li><li>n == grid[r].length</li><li>2 <= n <= 50</li><li>0 <= grid[r][c] <= 100</li></ul><p>来源:力扣(LeetCode)<br>链接:<a href="https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/">https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/</a><br>著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。</p><h2 id="解题思路"><a href="#解题思路" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>正视(先列中最大)和侧视(先行中最大)的最大值,再求n*n根据两个组的最小数赋值给[i,j],即为当前的楼最低点,算与真实的差值即为加高层数</p></blockquote><h2 id="解题代码"><a href="#解题代码" class="headerlink" title="解题代码"></a>解题代码</h2><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">class Solution {public: int maxIncreaseKeepingSkyline(vector<vector<int>>& grid) { int n=grid.size(); //侧视图天际线最低 vector<int> row_max_min(n); //正视图天际线最低 vector<int> col_max_min(n); for(int i=0;i<n;i++){ int tmp=*max_element(grid[i].begin(),grid[i].end()); row_max_min[i]=tmp; } for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { col_max_min[j] = max(col_max_min[j], grid[i][j]); } } int res = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { res += min(col_max_min[j],row_max_min[i])-grid[i][j]; } } return res; }};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h2 id="题目807-保持城市天际线"><a href="#题目807-保持城市天际线" class="headerlink" title="题目807.保持城市天际线"></a>题目807.保持城市天际线</h2><p>难度:中等</p>
<p>给你一座由 n x n 个</summary>
<category term="数据结构与算法" scheme="http://tiawnen42.top/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://tiawnen42.top/tags/%E7%AE%97%E6%B3%95/"/>
<category term="leetcode" scheme="http://tiawnen42.top/tags/leetcode/"/>
</entry>
<entry>
<title>力扣2022-03-27</title>
<link href="http://tiawnen42.top/posts/fe37.html"/>
<id>http://tiawnen42.top/posts/fe37.html</id>
<published>2022-03-27T12:25:59.000Z</published>
<updated>2022-04-11T06:14:14.000Z</updated>
<content type="html"><![CDATA[<h2 id="题目704-二分查找"><a href="#题目704-二分查找" class="headerlink" title="题目704.二分查找"></a>题目704.二分查找</h2><p>难度:简单</p><p>给定一个 n 个元素有序的(升序)整型数组 nums 和一个目标值 target ,写一个函数搜索 nums 中的 target,如果目标值存在返回下标,否则返回 -1。</p><br>**示例 1:**<pre class="line-numbers language-none"><code class="language-none">输入: nums = [-1,0,3,5,9,12], target = 9输出: 4解释: 9 出现在 nums 中并且下标为 4<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p><strong>示例 2:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入: nums = [-1,0,3,5,9,12], target = 2输出: -1解释: 2 不存在 nums 中因此返回 -1<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p><strong>提示:</strong></p><ol><li>你可以假设 nums 中的所有元素是不重复的。</li><li>n 将在 [1, 10000]之间。</li><li>nums 的每个元素都将在 [-9999, 9999]之间。</li></ol><p>来源:力扣(LeetCode)<br>链接:<a href="https://leetcode-cn.com/problems/binary-search/">https://leetcode-cn.com/problems/binary-search/</a><br>著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。</p><h2 id="解题思路"><a href="#解题思路" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>两种方法,注意边界条件和更新条件</p></blockquote><h2 id="解题代码"><a href="#解题代码" class="headerlink" title="解题代码"></a>解题代码</h2><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">class Solution {public: // 定义target在左闭右开的区间里,即:[left, right] int search(vector<int> &nums, int target) { int head = 0; int rear = nums.size() - 1; int mid; while (head <= rear) { mid = (head + rear) / 2; if (nums[mid] == target) return mid; else if (nums[mid] < target) { head = mid + 1; // 注意 } else if (nums[mid] > target) { rear = mid - 1; } } return 0; } // 定义target在左闭右开的区间里,即:[left, right) int search2(vector<int>& nums, int target) { int left = 0; int right = nums.size(); // 定义target在左闭右开的区间里,即:[left, right) while (left < right) { // 因为left == right的时候,在[left, right)是无效的空间,所以使用 < int middle = left + ((right - left) >> 1); if (nums[middle] > target) { right = middle; // target 在左区间,在[left, middle)中 } else if (nums[middle] < target) { left = middle + 1; // target 在右区间,在[middle + 1, right)中 } else { // nums[middle] == target return middle; // 数组中找到目标值,直接返回下标 } } // 未找到目标值 return -1; }};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h2 id="题目704-二分查找"><a href="#题目704-二分查找" class="headerlink" title="题目704.二分查找"></a>题目704.二分查找</h2><p>难度:简单</p>
<p>给定一个 n 个元素有序的(升序)整型数组 num</summary>
<category term="数据结构与算法" scheme="http://tiawnen42.top/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://tiawnen42.top/tags/%E7%AE%97%E6%B3%95/"/>
<category term="leetcode" scheme="http://tiawnen42.top/tags/leetcode/"/>
</entry>
<entry>
<title>力扣2022-03-25</title>
<link href="http://tiawnen42.top/posts/3fb6.html"/>
<id>http://tiawnen42.top/posts/3fb6.html</id>
<published>2022-03-25T13:02:52.000Z</published>
<updated>2022-04-11T06:14:14.000Z</updated>
<content type="html"><![CDATA[<h2 id="题目"><a href="#题目" class="headerlink" title="题目"></a>题目</h2><ol start="217"><li>存在重复元素</li></ol><p>难度:简单</p><p><code>nums</code></p><p><strong>至少两次</strong></p><p><code>true</code></p><p><code>false</code></p><p><strong>示例 1:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:nums = [1,2,3,1]输出:true<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 2:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:nums = [1,2,3,4]输出:false<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 3:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:nums = [1,1,1,3,3,4,3,2,4,2]输出:true<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>提示:</strong></p><ul><li>1 <= nums.length <= 10<sup>5</sup></li><li>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></li></ul><p>来源:力扣(LeetCode)<br>链接:<a href="https://leetcode-cn.com/problems/contains-duplicate/">https://leetcode-cn.com/problems/contains-duplicate/</a><br>著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。</p><h2 id="解题思路"><a href="#解题思路" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>排序,有相同的肯定近邻</p></blockquote><h2 id="解题代码"><a href="#解题代码" class="headerlink" title="解题代码"></a>解题代码</h2><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">class Solution {public: bool containsDuplicate(vector<int>& nums) { sort(nums.begin(), nums.end()); while(nums.size()>1&&(nums[nums.size()-1]!=nums[nums.size()-2])){ // 判断栈顶和倒二是否相等,注意边界条件 nums.pop_back(); } // for(int i=0; i<nums.size();i++){ // cout << nums[i] << " "; // } if(nums.size()==1) return false;else return true; }};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h2 id="题目"><a href="#题目" class="headerlink" title="题目"></a>题目</h2><ol start="217">
<li>存在重复元素</li>
</ol>
<p>难度:简单</p>
<p><code>nums</code><</summary>
<category term="数据结构与算法" scheme="http://tiawnen42.top/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://tiawnen42.top/tags/%E7%AE%97%E6%B3%95/"/>
<category term="leetcode" scheme="http://tiawnen42.top/tags/leetcode/"/>
</entry>
<entry>
<title>2021归档</title>
<link href="http://tiawnen42.top/posts/b2d9.html"/>
<id>http://tiawnen42.top/posts/b2d9.html</id>
<published>2022-03-21T03:04:22.000Z</published>
<updated>2022-06-30T08:02:52.000Z</updated>
<content type="html"><![CDATA[<p>堆了个奇怪的雪人</p><p><img src="http://qiniu.tianwen42.top/picgo/IMG_20201229_200725.jpg" alt="IMG_20201229_200725"></p><p>秦淮河畔</p><p><img src="http://qiniu.tianwen42.top/picgo/IMG_20210429_191925.jpg" alt="IMG_20210429_191925"></p><p><img src="http://qiniu.tianwen42.top/picgo/IMG_20211017_113126.jpg" alt="IMG_20211017_113126"></p><p><img src="http://qiniu.tianwen42.top/picgo/0009.jpg" alt="0009"><img src="http://qiniu.tianwen42.top/picgo/%5BThumb%5D640326600415-3ec0b87c-0587-317d-862b-68d4c1744c4f.jpg" alt="[Thumb]640326600415-3ec0b87c-0587-317d-862b-68d4c1744c4f" /></p><img src="http://qiniu.tianwen42.top/picgo/mmexport1641051034837.jpg" alt="mmexport1641051034837" style="zoom:50%;" /><p><img src="http://qiniu.tianwen42.top/picgo/mmexport1642862346561.jpg" alt="mmexport1642862346561"><img src="http://qiniu.tianwen42.top/picgo/mmexport1640590404629.jpg" alt="mmexport1640590404629"></p><p><img src="http://qiniu.tianwen42.top/picgo/IMG_20220125_130126.jpg" alt="IMG_20220125_130126"></p><p>分割线,听首歌吧</p><iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=530 height=86 src="//music.163.com/outchain/player?type=2&id=26494698&auto=0&height=66"></iframe>]]></content>
<summary type="html"><p>堆了个奇怪的雪人</p>
<p><img src="http://qiniu.tianwen42.top/picgo/IMG_20201229_200725.jpg" alt="IMG_20201229_200725"></p>
<p>秦淮河畔</p>
<p><img sr</summary>
<category term="生活" scheme="http://tiawnen42.top/categories/%E7%94%9F%E6%B4%BB/"/>
<category term="归档" scheme="http://tiawnen42.top/tags/%E5%BD%92%E6%A1%A3/"/>
</entry>
<entry>
<title>力扣2022-03-03</title>
<link href="http://tiawnen42.top/posts/5d37.html"/>
<id>http://tiawnen42.top/posts/5d37.html</id>
<published>2022-03-03T08:02:22.000Z</published>
<updated>2022-04-11T06:14:14.000Z</updated>
<content type="html"><![CDATA[<h2 id="题目343-整数拆分"><a href="#题目343-整数拆分" class="headerlink" title="题目343. 整数拆分"></a>题目343. 整数拆分</h2><p>难度:中等</p><p>给定一个正整数 n ,将其拆分为 k 个 <strong>正整数</strong> 的和( k >= 2 ),并使这些整数的乘积最大化。</p><p>返回 <em>你可以获得的最大乘积</em> 。</p><p><strong>示例 1:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入: n = 2输出: 1解释: 2 = 1 + 1, 1 × 1 = 1。<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p><strong>示例 2:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入: n = 10输出: 36解释: 10 = 3 + 3 + 4, 3 × 3 × 4 = 36。<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p><strong>提示:</strong></p><ul><li>2 <= n <= 58</li></ul><p>来源:力扣(LeetCode)<br>链接:<a href="https://leetcode-cn.com/problems/integer-break/">https://leetcode-cn.com/problems/integer-break/</a><br>著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。</p><h2 id="解题思路"><a href="#解题思路" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>dp题目</p><p>dp[i] = max(dp[i], max((i - j) * j, dp[i - j] * j));</p><p>dp[i] 是依靠 dp[i - j]的状态,所以遍历i一定是从前向后遍历,先有dp[i - j]再有dp[i]</p></blockquote><h2 id="解题代码"><a href="#解题代码" class="headerlink" title="解题代码"></a>解题代码</h2><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">//动态规划class Solution {public: int integerBreak(int n) { if(n==2) return 1; vector<int> dp(n+1,0); dp[2] = 1; for(int i=3;i<=n;++i){ for(int j=1;j<i;++j) dp[i] = max(dp[i],max(dp[i-j]*j,(i-j)*j)); } return dp[n]; }};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">//贪心算法//时间复杂度O(n)//空间复杂度O(1)class Solution {public: int integerBreak(int n) { if (n == 2) return 1; if (n == 3) return 2; if (n == 4) return 4; int result = 1; while (n > 4) { result *= 3; n -= 3; } result *= n; return result; }};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h2 id="题目343-整数拆分"><a href="#题目343-整数拆分" class="headerlink" title="题目343. 整数拆分"></a>题目343. 整数拆分</h2><p>难度:中等</p>
<p>给定一个正整数 n ,将其拆分为 k 个 <s</summary>
<category term="数据结构与算法" scheme="http://tiawnen42.top/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://tiawnen42.top/tags/%E7%AE%97%E6%B3%95/"/>
<category term="leetcode" scheme="http://tiawnen42.top/tags/leetcode/"/>
<category term="dp" scheme="http://tiawnen42.top/tags/dp/"/>
</entry>
<entry>
<title>力扣2022-02-28</title>
<link href="http://tiawnen42.top/posts/676.html"/>
<id>http://tiawnen42.top/posts/676.html</id>
<published>2022-02-28T01:16:55.000Z</published>
<updated>2022-04-11T06:14:14.000Z</updated>
<content type="html"><![CDATA[<h2 id="题目7-整数反转"><a href="#题目7-整数反转" class="headerlink" title="题目7.整数反转"></a>题目7.整数反转</h2><p>难度:中等</p><p>给你一个 32 位的有符号整数 x ,返回将 x 中的数字部分反转后的结果。</p><p>如果反转后整数超过 32 位的有符号整数的范围 [−2<sup>31</sup>, 2<sup>31 </sup>− 1] ,就返回 0。</p><p><strong>假设环境不允许存储 64 位整数(有符号或无符号)。</strong></p><p><strong>示例 1:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:x = 123输出:321<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 2:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:x = -123输出:-321<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 3:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:x = 120输出:21<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 4:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:x = 0输出:0<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>提示:</strong></p><ul><li>-2<sup>31</sup> <= x <= 2<sup>31</sup> - 1</li></ul><p>来源:力扣(LeetCode)<br>链接:<a href="https://leetcode-cn.com/problems/reverse-integer/">https://leetcode-cn.com/problems/reverse-integer/</a><br>著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。</p><h2 id="解题思路"><a href="#解题思路" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>整数翻转,123 –> 3 * 10+2 –> 32 * 10+1 –>321</p><p>想到另一个整数拼接的思路 123 –> 123 * 10+1 –> 1231 * 10 +2 –> 12312 * 10 +3 –>123123</p><p>再一个就是整数对称的思路 123 –> 123 * 10+3 –> 1231 * 10 +2 –> 12312 * 10 +1 –>123321</p></blockquote><h2 id="解题代码"><a href="#解题代码" class="headerlink" title="解题代码"></a>解题代码</h2><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">//123 321//-123 -321//0 0#include <iostream>class Solution {public: int reverse2(int x) { int ans = 0; while(x != 0) { if(ans > INT_MAX || ans < INT_MIN) return 0; ans = ans * 10 + x % 10; x /= 10; } return ans; }};<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">//数字对称//123 123321//-8 -88//-10 -1001int symmetryReverse(int x) { using namespace std; int ans = x; while(x != 0) { if(ans > INT_MAX || ans < INT_MIN) return 0; ans = ans * 10 + x % 10; //cout<<ans<<endl; x /= 10; } return ans; }<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">//数字重复//105 105105//10 1010//1 11int digitalRepeated(int x) { using namespace std; int ans = x; int num = 1 + log10(x); //位数 for (int i = num - 1; i >= 0; i--) { if (ans == 0 || ans > INT_MAX || ans < INT_MIN) //用for要注意0或者溢出 return 0; int maxdigit = (int) pow(10, i); // cout<<ans<<endl; ans = ans * 10 + (x / maxdigit) % 10; x %= maxdigit; } return ans; }<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><blockquote><p>由这一题抽象出对数字的常规算法,详情见<a href="">数字切片</a></p></blockquote>]]></content>
<summary type="html"><h2 id="题目7-整数反转"><a href="#题目7-整数反转" class="headerlink" title="题目7.整数反转"></a>题目7.整数反转</h2><p>难度:中等</p>
<p>给你一个 32 位的有符号整数 x ,返回将 x 中的数字部分反转</summary>
<category term="数据结构与算法" scheme="http://tiawnen42.top/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://tiawnen42.top/tags/%E7%AE%97%E6%B3%95/"/>
<category term="leetcode" scheme="http://tiawnen42.top/tags/leetcode/"/>
<category term="数字切片" scheme="http://tiawnen42.top/tags/%E6%95%B0%E5%AD%97%E5%88%87%E7%89%87/"/>
</entry>
<entry>
<title>力扣2022-02-27</title>
<link href="http://tiawnen42.top/posts/236.html"/>
<id>http://tiawnen42.top/posts/236.html</id>
<published>2022-02-26T16:15:35.000Z</published>
<updated>2022-04-11T06:14:14.000Z</updated>
<content type="html"><![CDATA[<h2 id="题目1221-分割平衡字符串"><a href="#题目1221-分割平衡字符串" class="headerlink" title="题目1221.分割平衡字符串"></a>题目1221.分割平衡字符串</h2><p>难度:简单</p><p>在一个 <strong>平衡字符串</strong> 中,’L’ 和 ‘R’ 字符的数量是相同的。</p><p>给你一个平衡字符串 s,请你将它分割成尽可能多的平衡字符串。</p><p><strong>注意:</strong>分割得到的每个字符串都必须是平衡字符串,且分割得到的平衡字符串是原平衡字符串的连续子串。</p><p>返回可以通过分割得到的平衡字符串的 <strong>最大数量</strong> <strong>。</strong></p><p><strong>示例 1:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:s = "RLRRLLRLRL"输出:4解释:s 可以分割为 "RL"、"RRLL"、"RL"、"RL" ,每个子字符串中都包含相同数量的 'L' 和 'R' 。<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p><strong>示例 2:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:s = "RLLLLRRRLR"输出:3解释:s 可以分割为 "RL"、"LLLRRR"、"LR" ,每个子字符串中都包含相同数量的 'L' 和 'R' 。<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p><strong>示例 3:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:s = "LLLLRRRR"输出:1解释:s 只能保持原样 "LLLLRRRR".<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p><strong>示例 4:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:s = "RLRRRLLRLL"输出:2解释:s 可以分割为 "RL"、"RRRLLRLL" ,每个子字符串中都包含相同数量的 'L' 和 'R' 。<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p><strong>提示:</strong></p><ul><li>1 <= s.length <= 1000</li><li>s[i] = ‘L’ 或 ‘R’</li><li>s 是一个 <strong>平衡</strong> 字符串</li></ul><p>来源:力扣(LeetCode)<br>链接:<a href="https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/">https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/</a><br>著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。</p><h2 id="解题思路"><a href="#解题思路" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>上楼梯问题,L下一步R上一步,在平地上num+1</p><p>“括号匹配”问题,主要是栈操作,’R’进栈,’L’出栈,栈空则匹配成功,结果加一</p></blockquote><h2 id="解题代码"><a href="#解题代码" class="headerlink" title="解题代码"></a>解题代码</h2><pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token keyword">class</span> <span class="token class-name">Solution</span><span class="token punctuation">:</span> <span class="token keyword">def</span> <span class="token function">balancedStringSplit</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> s<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> <span class="token builtin">int</span><span class="token punctuation">:</span> s<span class="token operator">=</span><span class="token builtin">list</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span> stack<span class="token operator">=</span><span class="token punctuation">[</span><span class="token punctuation">]</span> high<span class="token punctuation">,</span>num<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">0</span> <span class="token keyword">while</span> s<span class="token punctuation">:</span> <span class="token keyword">if</span> s<span class="token punctuation">.</span>pop<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">!=</span><span class="token string">'R'</span><span class="token punctuation">:</span> high<span class="token operator">-=</span><span class="token number">1</span> <span class="token keyword">else</span><span class="token punctuation">:</span> high<span class="token operator">+=</span><span class="token number">1</span> <span class="token keyword">if</span> high<span class="token operator">==</span><span class="token number">0</span><span class="token punctuation">:</span> num<span class="token operator">+=</span><span class="token number">1</span> <span class="token keyword">return</span> num<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h2 id="题目1221-分割平衡字符串"><a href="#题目1221-分割平衡字符串" class="headerlink" title="题目1221.分割平衡字符串"></a>题目1221.分割平衡字符串</h2><p>难度:简单</p>
<p>在一个 <stro</summary>
<category term="数据结构与算法" scheme="http://tiawnen42.top/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
<category term="算法" scheme="http://tiawnen42.top/tags/%E7%AE%97%E6%B3%95/"/>
<category term="leetcode" scheme="http://tiawnen42.top/tags/leetcode/"/>
<category term="字符串" scheme="http://tiawnen42.top/tags/%E5%AD%97%E7%AC%A6%E4%B8%B2/"/>
<category term="贪心算法" scheme="http://tiawnen42.top/tags/%E8%B4%AA%E5%BF%83%E7%AE%97%E6%B3%95/"/>
</entry>
<entry>
<title>力扣 2022-02-26</title>
<link href="http://tiawnen42.top/posts/9ea3.html"/>
<id>http://tiawnen42.top/posts/9ea3.html</id>
<published>2022-02-25T16:47:06.000Z</published>
<updated>2022-04-11T06:14:14.000Z</updated>
<content type="html"><![CDATA[<h2 id="题目917-仅仅反转字母"><a href="#题目917-仅仅反转字母" class="headerlink" title="题目917.仅仅反转字母"></a>题目917.仅仅反转字母</h2><p>难度:简单</p><p>给你一个字符串 s ,根据下述规则反转字符串:</p><ul><li>所有非英文字母保留在原有位置。</li><li>所有英文字母(小写或大写)位置反转。</li></ul><p>返回反转后的 s<em> 。</em></p><p><strong>示例 1:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:s = "ab-cd"输出:"dc-ba"<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 2:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:s = "a-bC-dEf-ghIj"输出:"j-Ih-gfE-dCba"<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 3:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:s = "Test1ng-Leet=code-Q!"输出:"Qedo1ct-eeLg=ntse-T!"<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>提示</strong></p><ul><li>1 <= s.length <= 100</li><li>s 仅由 ASCII 值在范围 [33, 122] 的字符组成</li><li>s 不含 ‘"‘ 或 ‘\‘</li></ul><p>来源:力扣(LeetCode)<br>链接:<a href="https://leetcode-cn.com/problems/reverse-only-letters/">https://leetcode-cn.com/problems/reverse-only-letters/</a><br>著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。</p><h2 id="解题思路"><a href="#解题思路" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>双指针法遍历</p></blockquote><h2 id=""><a href="#" class="headerlink" title=""></a></h2><pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token keyword">class</span> <span class="token class-name">Solution</span><span class="token punctuation">:</span> <span class="token keyword">def</span> <span class="token function">reverseOnlyLetters</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> s<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> <span class="token builtin">str</span><span class="token punctuation">:</span> s<span class="token operator">=</span><span class="token builtin">list</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span> head<span class="token punctuation">,</span>tail<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token builtin">len</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token operator">-</span><span class="token number">1</span> <span class="token keyword">while</span><span class="token punctuation">(</span>head<span class="token operator"><</span>tail<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">if</span> s<span class="token punctuation">[</span>head<span class="token punctuation">]</span><span class="token punctuation">.</span>isalpha<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">and</span> s<span class="token punctuation">[</span>tail<span class="token punctuation">]</span><span class="token punctuation">.</span>isalpha<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> s<span class="token punctuation">[</span>head<span class="token punctuation">]</span><span class="token punctuation">,</span>s<span class="token punctuation">[</span>tail<span class="token punctuation">]</span><span class="token operator">=</span>s<span class="token punctuation">[</span>tail<span class="token punctuation">]</span><span class="token punctuation">,</span>s<span class="token punctuation">[</span>head<span class="token punctuation">]</span> <span class="token comment">#交换</span> head<span class="token operator">+=</span><span class="token number">1</span> tail<span class="token operator">-=</span><span class="token number">1</span> <span class="token keyword">elif</span> <span class="token punctuation">(</span>s<span class="token punctuation">[</span>head<span class="token punctuation">]</span><span class="token punctuation">.</span>isalpha<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">and</span> <span class="token punctuation">(</span>s<span class="token punctuation">[</span>tail<span class="token punctuation">]</span><span class="token punctuation">.</span>isalpha<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">==</span><span class="token boolean">False</span><span class="token punctuation">)</span><span class="token punctuation">:</span> tail<span class="token operator">-=</span><span class="token number">1</span> <span class="token keyword">elif</span> <span class="token punctuation">(</span>s<span class="token punctuation">[</span>head<span class="token punctuation">]</span><span class="token punctuation">.</span>isalpha<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">==</span><span class="token boolean">False</span><span class="token punctuation">)</span> <span class="token keyword">and</span> <span class="token punctuation">(</span>s<span class="token punctuation">[</span>tail<span class="token punctuation">]</span><span class="token punctuation">.</span>isalpha<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span> head<span class="token operator">+=</span><span class="token number">1</span> <span class="token keyword">elif</span> <span class="token punctuation">(</span>s<span class="token punctuation">[</span>head<span class="token punctuation">]</span><span class="token punctuation">.</span>isalpha<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">==</span><span class="token boolean">False</span><span class="token punctuation">)</span> <span class="token keyword">and</span> <span class="token punctuation">(</span>s<span class="token punctuation">[</span>tail<span class="token punctuation">]</span><span class="token punctuation">.</span>isalpha<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">==</span><span class="token boolean">False</span><span class="token punctuation">)</span><span class="token punctuation">:</span> head<span class="token operator">+=</span><span class="token number">1</span> tail<span class="token operator">-=</span><span class="token number">1</span> <span class="token keyword">return</span> <span class="token string">''</span><span class="token punctuation">.</span>join<span class="token punctuation">(</span>s<span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h2 id="题目917-仅仅反转字母"><a href="#题目917-仅仅反转字母" class="headerlink" title="题目917.仅仅反转字母"></a>题目917.仅仅反转字母</h2><p>难度:简单</p>
<p>给你一个字符串 s ,根据下述规则</summary>
<category term="数据结构与算法" scheme="http://tiawnen42.top/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
</entry>
<entry>
<title>力扣 2022-02-25</title>
<link href="http://tiawnen42.top/posts/9fe3.html"/>
<id>http://tiawnen42.top/posts/9fe3.html</id>
<published>2022-02-25T05:01:03.000Z</published>
<updated>2022-04-11T06:14:14.000Z</updated>
<content type="html"><![CDATA[<h2 id="题目509-斐波那契数"><a href="#题目509-斐波那契数" class="headerlink" title="题目509.斐波那契数"></a>题目509.斐波那契数</h2><p>难度:简单</p><p><strong>斐波那契数</strong> (通常用 F(n) 表示)形成的序列称为 <strong>斐波那契数列</strong> 。该数列由 0 和 1 开始,后面的每一项数字都是前面两项数字的和。也就是:</p><pre class="line-numbers language-none"><code class="language-none">F(0) = 0,F(1) = 1F(n) = F(n - 1) + F(n - 2),其中 n > 1<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p>给定 n ,请计算 F(n) 。</p><p><strong>示例 1:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:n = 2输出:1解释:F(2) = F(1) + F(0) = 1 + 0 = 1<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p><strong>示例 2:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:n = 3输出:2解释:F(3) = F(2) + F(1) = 1 + 1 = 2<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p><strong>示例 3:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入:n = 4输出:3解释:F(4) = F(3) + F(2) = 2 + 1 = 3<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p><strong>提示:</strong></p><ul><li>0 <= n <= 30</li></ul><p>来源:力扣(LeetCode)<br>链接:<a href="https://leetcode-cn.com/problems/fibonacci-number/">https://leetcode-cn.com/problems/fibonacci-number/</a><br>著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。</p><pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token comment">#递归法</span><span class="token keyword">class</span> <span class="token class-name">Solution</span><span class="token punctuation">:</span> <span class="token keyword">def</span> <span class="token function">fib</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> n<span class="token punctuation">:</span> <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> <span class="token builtin">int</span><span class="token punctuation">:</span> <span class="token keyword">if</span><span class="token punctuation">(</span>n<span class="token operator">==</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">:</span><span class="token keyword">return</span> <span class="token number">0</span> <span class="token keyword">elif</span><span class="token punctuation">(</span>n<span class="token operator">==</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">:</span><span class="token keyword">return</span> <span class="token number">1</span> <span class="token keyword">else</span><span class="token punctuation">:</span><span class="token keyword">return</span> self<span class="token punctuation">.</span>fib<span class="token punctuation">(</span>n<span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token operator">+</span>self<span class="token punctuation">.</span>fib<span class="token punctuation">(</span>n<span class="token operator">-</span><span class="token number">2</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p><img src="http://cdn.tianwen42.top/picgo/image-20220225133243080.png" alt="image-20220225133243080"></p><pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token comment">#通项法</span><span class="token keyword">import</span> math<span class="token keyword">class</span> <span class="token class-name">Solution</span><span class="token punctuation">:</span> <span class="token keyword">def</span> <span class="token function">fib</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> N<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token triple-quoted-string string">""" :type N: int :rtype: int """</span> sqrt5<span class="token operator">=</span>math<span class="token punctuation">.</span>sqrt<span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span> <span class="token keyword">return</span> <span class="token builtin">round</span><span class="token punctuation">(</span><span class="token builtin">pow</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token operator">+</span>sqrt5<span class="token punctuation">)</span><span class="token operator">/</span><span class="token number">2</span><span class="token punctuation">,</span>N<span class="token punctuation">)</span><span class="token operator">/</span>sqrt5<span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h2 id="题目509-斐波那契数"><a href="#题目509-斐波那契数" class="headerlink" title="题目509.斐波那契数"></a>题目509.斐波那契数</h2><p>难度:简单</p>
<p><strong>斐波那契数</strong</summary>
<category term="数据结构与算法" scheme="http://tiawnen42.top/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
<category term="斐波那契数列" scheme="http://tiawnen42.top/tags/%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0%E5%88%97/"/>
</entry>
<entry>
<title>力扣 2022-02-24</title>
<link href="http://tiawnen42.top/posts/a858.html"/>
<id>http://tiawnen42.top/posts/a858.html</id>
<published>2022-02-24T14:04:48.000Z</published>
<updated>2022-04-11T06:14:14.000Z</updated>
<content type="html"><![CDATA[<h2 id="题目13-罗马数字转整数"><a href="#题目13-罗马数字转整数" class="headerlink" title="题目13. 罗马数字转整数"></a>题目13. 罗马数字转整数</h2><p>难度:简单</p><p>罗马数字包含以下七种字符: I, V, X, L,C,D 和 M。</p><pre class="line-numbers language-none"><code class="language-none">字符 数值I 1V 5X 10L 50C 100D 500M 1000<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>例如, 罗马数字 2 写做 II ,即为两个并列的 1 。12 写做 XII ,即为 X + II 。 27 写做 XXVII, 即为 XX + V + II 。</p><p>通常情况下,罗马数字中小的数字在大的数字的右边。但也存在特例,例如 4 不写做 IIII,而是 IV。数字 1 在数字 5 的左边,所表示的数等于大数 5 减小数 1 得到的数值 4 。同样地,数字 9 表示为 IX。这个特殊的规则只适用于以下六种情况:</p><ul><li>I 可以放在 V (5) 和 X (10) 的左边,来表示 4 和 9。</li><li>X 可以放在 L (50) 和 C (100) 的左边,来表示 40 和 90。 </li><li>C 可以放在 D (500) 和 M (1000) 的左边,来表示 400 和 900。</li></ul><p>给定一个罗马数字,将其转换成整数。</p><p><strong>示例 1:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入: s = "III"输出: 3<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 2:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入: s = "IV"输出: 4<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 3:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入: s = "IX"输出: 9<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><p><strong>示例 4:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入: s = "LVIII"输出: 58解释: L = 50, V= 5, III = 3.<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p><strong>示例 5:</strong></p><pre class="line-numbers language-none"><code class="language-none">输入: s = "MCMXCIV"输出: 1994解释: M = 1000, CM = 900, XC = 90, IV = 4.<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><p><strong>提示:</strong></p><ul><li>1 <= s.length <= 15</li><li>s 仅含字符 (‘I’, ‘V’, ‘X’, ‘L’, ‘C’, ‘D’, ‘M’)</li><li>题目数据保证 s 是一个有效的罗马数字,且表示整数在范围 [1, 3999] 内</li><li>题目所给测试用例皆符合罗马数字书写规则,不会出现跨位等情况。</li><li>IL 和 IM 这样的例子并不符合题目要求,49 应该写作 XLIX,999 应该写作 CMXCIX 。</li><li>关于罗马数字的详尽书写规则,可以参考 <a href="https://b2b.partcommunity.com/community/knowledge/zh_CN/detail/10753/%E7%BD%97%E9%A9%AC%E6%95%B0%E5%AD%97#knowledge_article">罗马数字 - Mathematics </a>。</li></ul><p>来源:力扣(LeetCode)<br>链接:<a href="https://leetcode-cn.com/problems/roman-to-integer/">https://leetcode-cn.com/problems/roman-to-integer/</a><br>著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。</p><h2 id="解题思路"><a href="#解题思路" class="headerlink" title="解题思路"></a>解题思路</h2><blockquote><p>替换双位罗马字符,再映射</p></blockquote><h2 id="解题代码"><a href="#解题代码" class="headerlink" title="解题代码"></a>解题代码</h2><pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token keyword">class</span> <span class="token class-name">Solution</span><span class="token punctuation">:</span> <span class="token keyword">def</span> <span class="token function">romanToInt</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> s<span class="token punctuation">:</span> <span class="token builtin">str</span><span class="token punctuation">)</span> <span class="token operator">-</span><span class="token operator">></span> <span class="token builtin">int</span><span class="token punctuation">:</span> s <span class="token operator">=</span> s<span class="token punctuation">.</span>replace<span class="token punctuation">(</span><span class="token string">'CM'</span><span class="token punctuation">,</span> <span class="token string">'Q'</span><span class="token punctuation">)</span> s <span class="token operator">=</span> s<span class="token punctuation">.</span>replace<span class="token punctuation">(</span><span class="token string">'CD'</span><span class="token punctuation">,</span> <span class="token string">'W'</span><span class="token punctuation">)</span> s <span class="token operator">=</span> s<span class="token punctuation">.</span>replace<span class="token punctuation">(</span><span class="token string">'XC'</span><span class="token punctuation">,</span> <span class="token string">'E'</span><span class="token punctuation">)</span> s <span class="token operator">=</span> s<span class="token punctuation">.</span>replace<span class="token punctuation">(</span><span class="token string">'XL'</span><span class="token punctuation">,</span> <span class="token string">'R'</span><span class="token punctuation">)</span> s <span class="token operator">=</span> s<span class="token punctuation">.</span>replace<span class="token punctuation">(</span><span class="token string">'IX'</span><span class="token punctuation">,</span> <span class="token string">'T'</span><span class="token punctuation">)</span> s <span class="token operator">=</span> s<span class="token punctuation">.</span>replace<span class="token punctuation">(</span><span class="token string">'IV'</span><span class="token punctuation">,</span> <span class="token string">'Y'</span><span class="token punctuation">)</span> keys <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token string">'Q'</span> <span class="token punctuation">:</span> <span class="token number">900</span><span class="token punctuation">,</span> <span class="token string">'W'</span> <span class="token punctuation">:</span> <span class="token number">400</span><span class="token punctuation">,</span> <span class="token string">'E'</span> <span class="token punctuation">:</span> <span class="token number">90</span><span class="token punctuation">,</span> <span class="token string">'R'</span> <span class="token punctuation">:</span> <span class="token number">40</span><span class="token punctuation">,</span> <span class="token string">'T'</span> <span class="token punctuation">:</span> <span class="token number">9</span><span class="token punctuation">,</span> <span class="token string">'Y'</span> <span class="token punctuation">:</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token string">'M'</span> <span class="token punctuation">:</span> <span class="token number">1000</span><span class="token punctuation">,</span> <span class="token string">'D'</span> <span class="token punctuation">:</span> <span class="token number">500</span><span class="token punctuation">,</span> <span class="token string">'C'</span> <span class="token punctuation">:</span> <span class="token number">100</span><span class="token punctuation">,</span> <span class="token string">'L'</span> <span class="token punctuation">:</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token string">'X'</span> <span class="token punctuation">:</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">'V'</span> <span class="token punctuation">:</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token string">'I'</span> <span class="token punctuation">:</span> <span class="token number">1</span> <span class="token punctuation">}</span> ans <span class="token operator">=</span> <span class="token number">0</span> <span class="token keyword">for</span> ch <span class="token keyword">in</span> s<span class="token punctuation">:</span> ans <span class="token operator">+=</span> keys<span class="token punctuation">[</span>ch<span class="token punctuation">]</span> <span class="token keyword">return</span> ans<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h2 id="题目13-罗马数字转整数"><a href="#题目13-罗马数字转整数" class="headerlink" title="题目13. 罗马数字转整数"></a>题目13. 罗马数字转整数</h2><p>难度:简单</p>
<p>罗马数字包含以下七种字符: I</summary>
<category term="数据结构与算法" scheme="http://tiawnen42.top/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/"/>
<category term="数据结构" scheme="http://tiawnen42.top/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/"/>
</entry>
<entry>
<title>深入理解C指针</title>
<link href="http://tiawnen42.top/posts/e801.html"/>
<id>http://tiawnen42.top/posts/e801.html</id>
<published>2022-02-02T01:13:55.000Z</published>
<updated>2022-03-08T15:22:26.000Z</updated>
<content type="html"><![CDATA[<h3 id="指针"><a href="#指针" class="headerlink" title="指针"></a>指针</h3><blockquote><ol><li>普通指针</li><li><a href="####%E6%8C%87%E5%90%91const%E5%AF%B9%E8%B1%A1%E7%9A%84%E6%8C%87%E9%92%88">指向 const 对象的指针</a></li><li><a href="####%E6%8C%87%E5%90%91%E9%9D%9Econst%E5%AF%B9%E8%B1%A1%E7%9A%84const%E6%8C%87%E9%92%88">指向 非const 对象的 const 指针</a></li><li><a href="####%E6%8C%87%E5%90%91const%E5%AF%B9%E8%B1%A1%E7%9A%84const%E6%8C%87%E9%92%88">指向 const 对象的 const 指针</a></li></ol></blockquote><p>首先区分引用变量与指针的区别</p><blockquote><p>当创建一个变量时,通过变量名修改和指针修改的安全性不同</p></blockquote><p><img src="http://qiniu.tianwen42.top/picgo/image-20220303143051994.png" alt="image-20220303143051994"></p><h3 id="内存泄漏"><a href="#内存泄漏" class="headerlink" title="内存泄漏"></a>内存泄漏</h3><p>tips</p><ul><li><p>创建内存后一定记得free, malloc,free成对出现</p></li><li><p>指针创建后记得要初始化</p></li></ul><p>初始化静态或全局变量不能调用函数,如</p><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">static int *pi=malloc(sizeof(int)); //编译错误<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><p>改为</p><pre class="line-numbers language-c++" data-language="c++"><code class="language-c++">static int *pi;pi = malloc(sizeof(int));<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>]]></content>
<summary type="html"><h3 id="指针"><a href="#指针" class="headerlink" title="指针"></a>指针</h3><blockquote>
<ol>
<li>普通指针</li>
<li><a href="####%E6%8C%87%E5%90%91const%</summary>
<category term="基础" scheme="http://tiawnen42.top/categories/%E5%9F%BA%E7%A1%80/"/>
<category term="指针" scheme="http://tiawnen42.top/tags/%E6%8C%87%E9%92%88/"/>
</entry>
</feed>