-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.xml
1662 lines (1631 loc) · 171 KB
/
search.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
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>虚拟DOM</title>
<url>/2020/07/08/%E8%99%9A%E6%8B%9FDOM/</url>
<content><![CDATA[]]></content>
</entry>
<entry>
<title>前端|Angular & React & Vue 对比</title>
<url>/2020/07/13/Angular%20&%20React%20&%20Vue%20%E5%AF%B9%E6%AF%94/</url>
<content><![CDATA[<p>#相同点:</p>
<ol>
<li>单页应用程序</li>
<li>组建管理 Component</li>
<li>数据流动</li>
<li>后段API如何进行 路径如何处理</li>
<li>css/js/</li>
<li>webpeck</li>
</ol>
<p>#不同点:</p>
<ol>
<li>React - 面向网页显示<br> jsx - 组建都涵盖在这一个文件中(html / css/ js)<br> 整体设计变化不大<br> 容易潜入网页</li>
<li>Angular - 面向整体应用开发(应用开发)<ul>
<li>精简架构设计 提供TS (AngularJs以后)</li>
<li>html/cs/js 分开</li>
</ul>
</li>
<li>Vue 界面显示(类似React 但不用选择第三方插件 也没有太多选择)<ul>
<li>本身组建分开 简单</li>
<li>一直在追赶Angular</li>
<li>没有大公司的支持</li>
</ul>
</li>
</ol>
<p>##React & Vue:不断增加第三方插件</p>
<hr>
<p>#Angular</p>
<ol>
<li>多Component 后可以lazy mounting </li>
<li>嵌入多个moudule</li>
<li>Single Page Component(React类似) App Component - index.html<br> 3.1 Rounting: (单页应用开发之前 rount 是在后端,计算出html数据推送到前端。 ) <pre><code>* 单页应用,后段只管理数据
* Angular framework 里面(多个lib,api请求的lib,rounting moudule) 所以称之为架构
** Vue & React:lib 放在min-js 通过require加载</code></pre></li>
<li>Angular的标准化 让代码可以90%重用</li>
<li>TypeScript 微软主推(编程效率)</li>
<li>模版 代码 css可分<ul>
<li>React:JSX 混合</li>
<li>大型项目重要性</li>
</ul>
</li>
<li>API访问<ul>
<li>直接集成HTML dispution</li>
<li>开发环境需要share proxy,命令行配置</li>
<li>React 有一个proxy属性,设置自己API</li>
</ul>
</li>
</ol>
]]></content>
<categories>
<category>前端</category>
<category>React</category>
<category>Angular</category>
</categories>
<tags>
<tag>前端</tag>
<tag>Angular</tag>
<tag>React</tag>
</tags>
</entry>
<entry>
<title>前端|前端面试题</title>
<url>/2020/07/13/100%E9%81%93%E6%9C%89%E7%AD%94%E6%A1%88%E7%9A%84%E5%89%8D%E7%AB%AF%E9%9D%A2%E8%AF%95%E9%A2%98/</url>
<content><![CDATA[<p>来源:<a href="https://juejin.im/post/5f081d496fb9a07eb90cb5cf" target="_blank" rel="noopener">100道有答案的前端面试题</a></p>
<h1 id="算法"><a href="#算法" class="headerlink" title="算法"></a>算法</h1><h1 id="模版"><a href="#模版" class="headerlink" title="模版"></a>模版</h1><h2 id="React"><a href="#React" class="headerlink" title="React"></a>React</h2><h2 id="Vue"><a href="#Vue" class="headerlink" title="Vue"></a>Vue</h2><h1 id="语法"><a href="#语法" class="headerlink" title="语法"></a>语法</h1><p>#其他资源<br><a href="https://github.com/lgwebdream/FE-Interview" target="_blank" rel="noopener">前端面试星球</a><br><a href="https://github.com/sl1673495/leetcode-javascript" target="_blank" rel="noopener">Welcome to leetcode-javascript</a></p>
]]></content>
<categories>
<category>javascript</category>
<category>前端</category>
</categories>
<tags>
<tag>前端</tag>
<tag>javascript</tag>
</tags>
</entry>
<entry>
<title>前端| Angular 历史</title>
<url>/2020/07/13/Angular%E5%8E%86%E5%8F%B2/</url>
<content><![CDATA[<p>From : <a href="https://medium.com/@lifenshades/difference-among-angular-8-7-6-5-4-3-2-breakdown-new-features-and-changes-811fb5f8e6f0" target="_blank" rel="noopener">点我</a><br>#Angular 2(typescript)</p>
<ol>
<li>Component-based instead of Controller</li>
<li>ES6</li>
<li>Mobile (low-end) device</li>
</ol>
<p>#Angular 3</p>
<ol>
<li>single repo for everthiing @angular/core @angular/compiler @angular/router</li>
<li>router realsing (MonoRepo)</li>
</ol>
<p>#Angular 4</p>
<ol>
<li>underlying concecpt (same or inheritance from 2)</li>
<li>reduce size of AOT compiler</li>
<li>Typescript 2.1</li>
<li>seperate @angular/core to @angular/animation</li>
<li>block in *ngIF introduced:</li>
</ol>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">*ngIf=”yourCondition; else myFalsyTemplate”s</span><br><span class="line">“<ng-template #myFalsyTemplate>Else Html</ng-template>”</span><br></pre></td></tr></table></figure>
<p>#Angular 5</p>
<ol>
<li>HttpClient : a new modulr</li>
<li>exportAs: multiply names suport for both directives and component</li>
<li>new Router Life-cycle Events:<ul>
<li>ActivationStart, ActivationEnd,</li>
<li>ChildActivationStart, ChildActivationEnd,</li>
<li>GuardsCheckStart, GuardsCheckEnd, </li>
<li>ResolveStart and ResolveEnd.</li>
</ul>
</li>
</ol>
<p>#Angular 6</p>
<ol>
<li>More tool-chain and less underlying framework</li>
<li>RxJs 6</li>
<li>Synchronizes major version : <ul>
<li>Angular framework</li>
<li>Angular CLI</li>
<li>Angular Material + CDK</li>
<li><code><ng-template></code> instead of <code><template></code></li>
<li>Injectable</li>
<li>From <figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">// app.module.ts</span><br><span class="line">import {MyService} from './my-service';</span><br><span class="line">providers: [...MyService]</span><br></pre></td></tr></table></figure>
to <figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">// MyService.ts</span></span><br><span class="line">@Injectable({ <span class="attr">providedIn</span>: <span class="string">'root'</span>})</span><br><span class="line"><span class="keyword">export</span> <span class="class"><span class="keyword">class</span> <span class="title">MyService</span></span>{}</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li>#Angular 7</li>
</ol>
<p>#Angular 8 </p>
]]></content>
<categories>
<category>前端</category>
<category>Angular</category>
</categories>
<tags>
<tag>前端</tag>
<tag>Angular</tag>
</tags>
</entry>
<entry>
<title>前端|JavaScript面试</title>
<url>/2020/07/13/JavaScript%E9%9D%A2%E8%AF%95/</url>
<content><![CDATA[<p>#资源</p>
<ul>
<li><a href="https://juejin.im/post/5c36fe50518825253b5e94f4" target="_blank" rel="noopener">JavaScript设计模式总结</a></li>
<li><a href="https://juejin.im/entry/58c280b1da2f600d8725b887" target="_blank" rel="noopener">https://juejin.im/entry/58c280b1da2f600d8725b887</a></li>
<li><a href="https://zhuanlan.zhihu.com/p/51921749" target="_blank" rel="noopener">js设计模式:第一篇</a></li>
<li><a href="https://zhuanlan.zhihu.com/p/65398124" target="_blank" rel="noopener">[译] 现代 JavaScript 开发中的设计模式</a></li>
<li><a href="https://juejin.im/post/5c36fe50518825253b5e94f4" target="_blank" rel="noopener">一位前端 2018 绝地求生记 | 掘金年度征文</a></li>
<li><a href="https://juejin.im/post/5e7af0685188255dcf4a497e" target="_blank" rel="noopener">写给女朋友的中级前端面试秘籍(含详细答案,15k级别)</a></li>
</ul>
<p>#React</p>
<ul>
<li><a href="https://liangjunrong.github.io/JavaScript-library/React/React-demo-four-JueJin.html" target="_blank" rel="noopener">React Demo Four - 掘金</a></li>
</ul>
<p>#Angular</p>
<ul>
<li><a href="https://juejin.im/post/5b10aeca6fb9a01e54375566" target="_blank" rel="noopener">浅谈 Angular 项目实战</a></li>
</ul>
<h1 id="Framework"><a href="#Framework" class="headerlink" title="Framework"></a>Framework</h1><ul>
<li><a href="https://www.jianshu.com/p/0805128b4e27" target="_blank" rel="noopener">F7+Vue+WebPack移动端单页应用脚手架</a></li>
</ul>
<p>#CORDOVA</p>
<ul>
<li><a href="https://cordova.axuer.com/docs/zh-cn/latest/cordova/events/events.html#volumeupbutton按下增加声音按钮" target="_blank" rel="noopener">cordova</a></li>
</ul>
]]></content>
<categories>
<category>前端</category>
<category>javascript</category>
</categories>
<tags>
<tag>前端</tag>
<tag>Angular</tag>
<tag>React</tag>
</tags>
</entry>
<entry>
<title>前端|DOM |虚拟DOM</title>
<url>/2020/07/13/JS-DOM-%E8%99%9A%E6%8B%9FDOM/</url>
<content><![CDATA[<h1 id="DOM"><a href="#DOM" class="headerlink" title="DOM"></a>DOM</h1>]]></content>
<categories>
<category>前端</category>
<category>javascript</category>
<category>DOM</category>
</categories>
<tags>
<tag>前端</tag>
<tag>javascript</tag>
<tag>DOM</tag>
</tags>
</entry>
<entry>
<title>LeetCode|Array|350 Intersection_of_Two_Arrays_II</title>
<url>/2020/07/14/LeetCode_Array_350_Intersection_of_Two_Arrays_II/</url>
<content><![CDATA[<h1 id="题目"><a href="#题目" class="headerlink" title="题目"></a><a href="https://leetcode.com/problems/intersection-of-two-arrays-ii/" target="_blank" rel="noopener">题目</a></h1><p>Given two arrays, write a function to compute their intersection.</p>
<p>Example 1:</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">Input: nums1 = [1,2,2,1], nums2 = [2,2]</span><br><span class="line">Output: [2,2]</span><br></pre></td></tr></table></figure>
<p>Example 2:</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]</span><br><span class="line">Output: [4,9]</span><br></pre></td></tr></table></figure>
<p>Note:</p>
<p>Each element in the result should appear as many times as it shows in both arrays.<br>The result can be in any order.<br>Follow up:</p>
<p>What if the given array is already sorted? How would you optimize your algorithm?<br>What if nums1’s size is small compared to nums2’s size? Which algorithm is better?<br>What if elements of nums2 are stored on disk, and the memory is limited such that you cannot load all elements into the memory at once?</p>
<h1 id="解题思路"><a href="#解题思路" class="headerlink" title="解题思路"></a>解题思路</h1><h3 id="需要内存,不需要排序"><a href="#需要内存,不需要排序" class="headerlink" title="需要内存,不需要排序"></a>需要内存,不需要排序</h3><h4 id="HASHMAP"><a href="#HASHMAP" class="headerlink" title="HASHMAP"></a>HASHMAP</h4><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{number[]}</span> <span class="variable">nums1</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{number[]}</span> <span class="variable">nums2</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return <span class="type">{number[]}</span></span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">var</span> intersect = <span class="function"><span class="keyword">function</span>(<span class="params">nums1, nums2</span>) </span>{</span><br><span class="line"> <span class="keyword">let</span> map1 = countNums(nums1);</span><br><span class="line"> <span class="keyword">let</span> map2 = countNums(nums2);</span><br><span class="line"> <span class="keyword">let</span> res = [];</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">let</span> num <span class="keyword">of</span> map1.keys()){</span><br><span class="line"> <span class="keyword">const</span> count = <span class="built_in">Math</span>.min(map1.get(num), map2.get(num));</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">let</span> i = <span class="number">0</span>; i < count; i++){</span><br><span class="line"> res.push(num);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> res;</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">countNums</span>(<span class="params">nums</span>)</span>{</span><br><span class="line"> <span class="keyword">let</span> map = <span class="keyword">new</span> <span class="built_in">Map</span>()</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">let</span> i = <span class="number">0</span>; i < nums.length; i++){</span><br><span class="line"> <span class="keyword">let</span> num = nums[i];</span><br><span class="line"> <span class="keyword">let</span> count = map.get(num);</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">if</span>(count){</span><br><span class="line"> map.set(num, count + <span class="number">1</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> map.set(num, <span class="number">1</span>);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> map;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h4 id="Array"><a href="#Array" class="headerlink" title="Array"></a>Array</h4><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{number[]}</span> <span class="variable">nums1</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{number[]}</span> <span class="variable">nums2</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return <span class="type">{number[]}</span></span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">var</span> intersect = <span class="function"><span class="keyword">function</span> (<span class="params">nums1, nums2</span>) </span>{</span><br><span class="line"> <span class="keyword">let</span> solution = [];</span><br><span class="line"> <span class="keyword">if</span> (nums1.length < nums2.length) {</span><br><span class="line"> <span class="keyword">return</span> intersect(nums2, nums1);</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// Instead of HashMap, nums1 to acculate</span></span><br><span class="line"> <span class="comment">// [1, 2, 2, 1]</span></span><br><span class="line"> <span class="comment">// {'1':2, '2':2} </span></span><br><span class="line"> <span class="keyword">const</span> obj = nums1.reduce(<span class="function">(<span class="params">acc, num</span>) =></span> {</span><br><span class="line"> acc[num] = acc[num] + <span class="number">1</span> || <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">return</span> acc;</span><br><span class="line"> }, {});</span><br><span class="line"> </span><br><span class="line"> <span class="comment">//find the num in nums2</span></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span>; i < nums2.length; i++) {</span><br><span class="line"> <span class="keyword">if</span> (obj[nums2[i]] !== <span class="literal">undefined</span> && obj[nums2[i]] > <span class="number">0</span>) {</span><br><span class="line"> obj[nums2[i]] = obj[nums2[i]] - <span class="number">1</span>;</span><br><span class="line"> solution.push(nums2[i]);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> solution;</span><br><span class="line">};</span><br></pre></td></tr></table></figure>
<h3 id="需要排序"><a href="#需要排序" class="headerlink" title="需要排序"></a>需要排序</h3><h4 id="双指针解题"><a href="#双指针解题" class="headerlink" title="双指针解题"></a>双指针解题</h4><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{number[]}</span> <span class="variable">nums1</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{number[]}</span> <span class="variable">nums2</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return <span class="type">{number[]}</span></span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">var</span> intersect = <span class="function"><span class="keyword">function</span>(<span class="params">nums1, nums2</span>) </span>{</span><br><span class="line"> <span class="keyword">let</span> res = [];</span><br><span class="line"> </span><br><span class="line"> <span class="comment">//Sort array</span></span><br><span class="line"> nums1.sort(<span class="function">(<span class="params">a, b</span>) =></span> a - b);</span><br><span class="line"> nums2.sort(<span class="function">(<span class="params">a, b</span>) =></span> a - b);</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">let</span> i = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">let</span> j = <span class="number">0</span>;</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">while</span>(i<nums1.length && j< nums2.length){</span><br><span class="line"> <span class="keyword">let</span> x = nums1[i];</span><br><span class="line"> <span class="keyword">let</span> y = nums2[j];</span><br><span class="line"> <span class="keyword">if</span>(x === y){</span><br><span class="line"> res.push(nums1[i]);</span><br><span class="line"> i++;</span><br><span class="line"> j++;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>(x > y){</span><br><span class="line"> j++;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> <span class="comment">// x < y;</span></span><br><span class="line"> i++;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">return</span> res;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
]]></content>
<categories>
<category>LeetCode刷题</category>
<category>数据结构,数组</category>
</categories>
<tags>
<tag>Array</tag>
<tag>LeetCode</tag>
</tags>
</entry>
<entry>
<title>LeetCode| Array |Two Pointers| Stack|42. Trapping Rain Water</title>
<url>/2020/07/17/LeetCode%7CArray%7CTwo%20Pointers%7CStack%7C42.%20Trapping%20Rain%20Water/</url>
<content><![CDATA[<h1 id="Problem"><a href="#Problem" class="headerlink" title="Problem "></a><a href="https://leetcode.com/problems/trapping-rain-water/" target="_blank" rel="noopener">Problem </a></h1><p>Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.</p>
<p><img src="/2020/07/17/LeetCode|Array|Two%20Pointers|Stack|42.%20Trapping%20Rain%20Water/LeetCode_Greedy_455_AssignCookies.png" alt></p>
<p>The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for contributing this image!</p>
<p>Example:</p>
<blockquote>
<p>Input: [0,1,0,2,1,0,1,3,2,1,2,1]<br>Output: 6</p>
</blockquote>
<h1 id="Solve"><a href="#Solve" class="headerlink" title="Solve"></a>Solve</h1><p>左右 底部 三个点<br>左边最大 - 底部<br>右边最大 - 底部 </p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{number[]}</span> <span class="variable">height</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return <span class="type">{number}</span></span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">var</span> trap = <span class="function"><span class="keyword">function</span>(<span class="params">height</span>) </span>{</span><br><span class="line"> <span class="keyword">let</span> left = <span class="number">0</span>, right = height.length <span class="number">-1</span>;</span><br><span class="line"> <span class="keyword">let</span> leftMax = <span class="number">-1</span>, rightMax = <span class="number">-1</span>;</span><br><span class="line"> <span class="keyword">let</span> res = <span class="number">0</span>;</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">while</span>(left < right){</span><br><span class="line"> leftMax = height[left] > leftMax ? height[left] : leftMax;</span><br><span class="line"> rightMax = height[right] > rightMax ? height[right] : rightMax;</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">if</span>(leftMax > rightMax){</span><br><span class="line"> res += rightMax - height[right];</span><br><span class="line"> right --;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> res += leftMax - height[left];</span><br><span class="line"> left ++;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> res;</span><br><span class="line">};</span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category>LeetCode刷题</category>
</categories>
</entry>
<entry>
<title>LeetCode|Graph| 133 Clone Graph</title>
<url>/2020/07/14/LeetCode%7CGraph%7C133_%20Clone_Graph/</url>
<content><![CDATA[<hr>
<h1 id="题目"><a href="#题目" class="headerlink" title="题目"></a><a href="https://leetcode.com/problems/clone-graph/" target="_blank" rel="noopener">题目</a></h1><p>Given a reference of a node in a connected undirected graph.</p>
<p>Return a deep copy (clone) of the graph.</p>
<p>Each node in the graph contains a val (int) and a list (List[Node]) of its neighbors.</p>
<blockquote>
<p>class Node {<br> public int val;<br> public List<Node> neighbors;<br>}</Node></p>
</blockquote>
<p>Test case format:</p>
<p>For simplicity sake, each node’s value is the same as the node’s index (1-indexed). For example, the first node with val = 1, the second node with val = 2, and so on. The graph is represented in the test case using an adjacency list.</p>
<p>Adjacency list is a collection of unordered lists used to represent a finite graph. Each list describes the set of neighbors of a node in the graph.</p>
<p>The given node will always be the first node with val = 1. You must return the copy of the given node as a reference to the cloned graph.</p>
<p>Example 1:<br><img src="/2020/07/14/LeetCode|Graph|133_%20Clone_Graph/Cypress_Field_Rendering.png" alt></p>
<blockquote>
<p>Input: adjList = [[2,4],[1,3],[2,4],[1,3]]<br>Output: [[2,4],[1,3],[2,4],[1,3]]<br>Explanation: There are 4 nodes in the graph.<br>1st node (val = 1)’s neighbors are 2nd node (val = 2) and 4th node (val = 4).<br>2nd node (val = 2)’s neighbors are 1st node (val = 1) and 3rd node (val = 3).<br>3rd node (val = 3)’s neighbors are 2nd node (val = 2) and 4th node (val = 4).<br>4th node (val = 4)’s neighbors are 1st node (val = 1) and 3rd node (val = 3).</p>
</blockquote>
<p>Example 2:<br><img src="/2020/07/14/LeetCode|Graph|133_%20Clone_Graph/graph.png" alt></p>
<blockquote>
<p>Input: adjList = [[]]<br>Output: [[]]<br>Explanation: Note that the input contains one empty list. The graph consists of only one node with val = 1 and it does not have any neighbors.</p>
</blockquote>
<p>Example 3:</p>
<blockquote>
<p>Input: adjList = []<br>Output: []<br>Explanation: This an empty graph, it does not have any nodes.</p>
</blockquote>
<p>Example 4:<br><img src="/2020/07/14/LeetCode|Graph|133_%20Clone_Graph/graph-1.png" alt></p>
<blockquote>
<p>Input: adjList = [[2],[1]]<br>Output: [[2],[1]]</p>
</blockquote>
<p>Constraints:</p>
<p>1 <= Node.val <= 100<br>Node.val is unique for each node.<br>Number of Nodes will not exceed 100.<br>There is no repeated edges and no self-loops in the graph.<br>The Graph is connected and all nodes can be visited starting from the given node.</p>
<h1 id="solve"><a href="#solve" class="headerlink" title="solve"></a>solve</h1><h2 id="DFS"><a href="#DFS" class="headerlink" title="DFS"></a>DFS</h2><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * // Definition for a Node.</span></span><br><span class="line"><span class="comment"> * function Node(val, neighbors) {</span></span><br><span class="line"><span class="comment"> * this.val = val === undefined ? 0 : val;</span></span><br><span class="line"><span class="comment"> * this.neighbors = neighbors === undefined ? [] : neighbors;</span></span><br><span class="line"><span class="comment"> * };</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{Node}</span> <span class="variable">node</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return <span class="type">{Node}</span></span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// DFS</span></span><br><span class="line"><span class="keyword">var</span> cloneGraph = <span class="function"><span class="keyword">function</span>(<span class="params">node</span>) </span>{</span><br><span class="line"> <span class="keyword">if</span>(node === <span class="literal">null</span>){</span><br><span class="line"> <span class="keyword">return</span> node;</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> map = <span class="keyword">new</span> <span class="built_in">Map</span>();</span><br><span class="line"> <span class="keyword">const</span> clone = <span class="function"><span class="params">root</span> =></span>{</span><br><span class="line"> <span class="keyword">if</span>( !map.has(root.val) ){</span><br><span class="line"> map.set(root.val, <span class="keyword">new</span> Node(root.val) );</span><br><span class="line"> map.get(root.val).neighbors = root.neighbors.map(clone);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> map.get(root.val);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> clone(node);</span><br><span class="line">};</span><br></pre></td></tr></table></figure>
<h2 id="迭代模版"><a href="#迭代模版" class="headerlink" title="迭代模版"></a>迭代模版</h2><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> cloneGraph = <span class="function"><span class="keyword">function</span>(<span class="params">node</span>) </span>{</span><br><span class="line"> <span class="keyword">if</span>(!node){</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">const</span> queue = [node], visited = <span class="keyword">new</span> <span class="built_in">Map</span>();</span><br><span class="line"></span><br><span class="line"> visited.set(node, <span class="keyword">new</span> Node(node.val))</span><br><span class="line"> <span class="keyword">while</span>(queue.length > <span class="number">0</span> ){</span><br><span class="line"> <span class="keyword">const</span> curr = queue.pop()</span><br><span class="line"> curr.neighbors.forEach(<span class="function"><span class="params">neigbor</span> =></span>{</span><br><span class="line"> <span class="keyword">if</span>(!visited.has(neigbor)){</span><br><span class="line"> visited.set(neigbor, <span class="keyword">new</span> Node(neigbor.val))</span><br><span class="line"> queue.unshift(neigbor)</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">const</span> cloned = visited.get(curr)</span><br><span class="line"> <span class="keyword">const</span> cloneN = visited.get(neigbor)</span><br><span class="line"> cloned.neighbors.push(cloneN)</span><br><span class="line"> });</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">return</span> visited.get(node);</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category>LeetCode刷题</category>
<category>数据结构</category>
<category>图</category>
</categories>
<tags>
<tag>LeetCode</tag>
<tag>Graph"</tag>
</tags>
</entry>
<entry>
<title>LeetCode|Greedy|455 Assign Cookies</title>
<url>/2020/07/14/LeetCode%7CGreedy%7C455_Assign%20Cookies/</url>
<content><![CDATA[<h1 id="Problem"><a href="#Problem" class="headerlink" title="Problem"></a>Problem</h1><p>Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a cookie that the child will be content with; and each cookie j has a size sj. If sj >= gi, we can assign the cookie j to the child i, and the child i will be content. Your goal is to maximize the number of your content children and output the maximum number.</p>
<p>Note:<br>You may assume the greed factor is always positive.<br>You cannot assign more than one cookie to one child.</p>
<p>Example 1:</p>
<blockquote>
<p>Input: [1,2,3], [1,1]</p>
<p>Output: 1</p>
<p>Explanation: You have 3 children and 2 cookies. The greed factors of 3 children are 1, 2, 3.<br>And even though you have 2 cookies, since their size is both 1, you could only make the child whose greed factor is 1 content.<br>You need to output 1.</p>
</blockquote>
<p>Example 2:</p>
<blockquote>
<p>Input: [1,2], [1,2,3]</p>
<p>Output: 2</p>
<p>Explanation: You have 2 children and 3 cookies. The greed factors of 2 children are 1, 2.<br>You have 3 cookies and their sizes are big enough to gratify all of the children,<br>You need to output 2.</p>
</blockquote>
<h1 id="Solve"><a href="#Solve" class="headerlink" title="Solve"></a>Solve</h1><h3 id="itr"><a href="#itr" class="headerlink" title="itr"></a>itr</h3><p>饼干和孩子的需求都排序好,然后从最小的饼干分配给需求最小的孩子开始,不断的尝试新的饼干和新的孩子,这样能保证每个分给孩子的饼干都恰到好处的不浪费,又满足需求。</p>
<p>利用双指针不断的更新 i 孩子的需求下标和 j饼干的值,直到两者有其一达到了终点位置:</p>
<p>如果当前的饼干不满足孩子的胃口,那么把 j++ 寻找下一个饼干,不用担心这个饼干被浪费,因为这个饼干更不可能满足下一个孩子(胃口更大)。<br>如果满足,那么 i++; j++; count++ 记录当前的成功数量,继续寻找下一个孩子和下一个饼干。</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{number[]}</span> <span class="variable">g</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{number[]}</span> <span class="variable">s</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return <span class="type">{number}</span></span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">var</span> findContentChildren = <span class="function"><span class="keyword">function</span>(<span class="params">g, s</span>) </span>{</span><br><span class="line"> g.sort(<span class="function">(<span class="params">a,b</span>) =></span> a - b)</span><br><span class="line"> s.sort(<span class="function">(<span class="params">a,b</span>) =></span> a - b)</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">let</span> i = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">let</span> j = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">let</span> count = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">while</span>(i < g.length && j < s.length){</span><br><span class="line"> <span class="keyword">let</span> need = g[i];</span><br><span class="line"> <span class="keyword">let</span> cookie = s[j];</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">if</span>(cookie >= need){</span><br><span class="line"> count ++;</span><br><span class="line"> i++;</span><br><span class="line"> j++;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> j++;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">return</span> count;</span><br><span class="line">};</span><br></pre></td></tr></table></figure>
<h3 id="Resource"><a href="#Resource" class="headerlink" title="Resource"></a>Resource</h3><p><a href="https://mp.weixin.qq.com/s/7mJSpnHE319swy0LStpavQ" target="_blank" rel="noopener">here</a></p>
]]></content>
<categories>
<category>LeetCode刷题</category>
<category>Greedy</category>
</categories>
<tags>
<tag>LeetCode</tag>
<tag>Greedy"</tag>
</tags>
</entry>
<entry>
<title>LeetCode|Greedy|200 Number of Islands</title>
<url>/2020/07/15/LeetCode%7CGreedy%7C200%20Number%20of%20Islands%20/</url>
<content><![CDATA[<h1 id="Problem"><a href="#Problem" class="headerlink" title="Problem"></a>Problem</h1><p>Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.</p>
<p>Example 1:</p>
<blockquote>
<p>Input: grid = [<br> [“1”,”1”,”1”,”1”,”0”],<br> [“1”,”1”,”0”,”1”,”0”],<br> [“1”,”1”,”0”,”0”,”0”],<br> [“0”,”0”,”0”,”0”,”0”]<br>]<br>Output: 1</p>
</blockquote>
<p>Example 2:</p>
<p><code>Input: grid = [
["1","1","0","0","0"],
["1","1","0","0","0"],
["0","0","1","0","0"],
["0","0","0","1","1"]
]
Output: 3</code></p>
<h1 id="Solve"><a href="#Solve" class="headerlink" title="Solve"></a>Solve</h1><p><a href="https://leetcode.com/problems/number-of-islands/discuss/429842/JavaScript-DFS-Commented-Thought-Process-Beats-100-Time-and-Space" target="_blank" rel="noopener">here</a></p>
<p>Below is what I typed out on a google doc in preparation for a google phone interview.<br>I thought it may be helpful for others to see and give feedback on my thought process, and if it makes sense/is followable. After all, that’s what I want my interviewer to do, understand me.<br>Goal: Count number of islands<br>Rules:</p>
<p>An island is surrounded by water(0’s)<br>We count things apart of our island if it is horizontal or vertical connected<br>Plan:<br>Start at the top left of the 2d array, and visit the first row, and all its columns, trying to find the start of the first island<br>Once we find a 1, we can increment the number of islands, but we want to know where the island ends. So let’s look and follow any of the horizontal or vertical spots near the current position we are on.<br>First, let’s mark the current start/visited parts of the islands as visited by turning them into a 0,<br>Second, explore all the adjacent possibilities,<br>If one of them is a 1, recursively turn it into a 0 and check its children<br>Once we are done, we should have gotten rid of the island that we discovered and can move on to the next island, if it exists in the 2d array</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{character[][]}</span> <span class="variable">grid</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return <span class="type">{number}</span></span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">var</span> numIslands = <span class="function"><span class="keyword">function</span>(<span class="params">grid</span>) </span>{</span><br><span class="line"> <span class="keyword">if</span>(!grid)</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">let</span> res = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">let</span> m =<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">let</span> n = <span class="number">0</span>;</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">let</span> i = <span class="number">0</span>; i < grid.length; i++){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">let</span> j = <span class="number">0</span>; j < grid[i].length; j++){</span><br><span class="line"> res += grid[i][j] -<span class="string">"0"</span>;</span><br><span class="line"> dfs(i, j, grid);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> res;</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">dfs</span>(<span class="params">x, y, array</span>)</span>{</span><br><span class="line"> <span class="keyword">if</span>(x<<span class="number">0</span> || y< <span class="number">0</span>|| x>= array.length || y>= array[<span class="number">0</span>].length || array[x][y] ===<span class="string">"0"</span>){</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line">}</span><br><span class="line"> array[x][y] = <span class="string">"0"</span>;</span><br><span class="line"> dfs(x<span class="number">-1</span>, y, array);</span><br><span class="line"> dfs(x+<span class="number">1</span>, y, array);</span><br><span class="line"> dfs(x, y<span class="number">-1</span>, array);</span><br><span class="line"> dfs(x, y+<span class="number">1</span>, array);</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
]]></content>
<categories>
<category>LeetCode刷题</category>
<category>DFS</category>
</categories>
<tags>
<tag>LeetCode</tag>
<tag>DFS"</tag>
</tags>
</entry>
<entry>
<title>LeetCode|String|20 ValidParentheses</title>
<url>/2020/07/14/LeetCode%7CString%7C20_ValidParentheses/</url>
<content><![CDATA[<h1 id="Problem"><a href="#Problem" class="headerlink" title="Problem"></a>Problem</h1><p>Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, determine if the input string is valid.</p>
<p>An input string is valid if:</p>
<p>Open brackets must be closed by the same type of brackets.<br>Open brackets must be closed in the correct order.<br>Note that an empty string is also considered valid.</p>
<p>Example 1:</p>
<blockquote>
<p>Input: “()”<br>Output: true</p>
</blockquote>
<p>Example 2:</p>
<blockquote>
<p>Input: “()[]{}”<br>Output: true</p>
</blockquote>
<p>Example 3:</p>
<blockquote>
<p>Input: “(]”<br>Output: false</p>
</blockquote>
<p>Example 4:</p>
<blockquote>
<p>Input: “([)]”<br>Output: false</p>
</blockquote>
<p>Example 5:</p>
<blockquote>
<p>Input: “{[]}”<br>Output: true</p>
</blockquote>
<h1 id="Solve"><a href="#Solve" class="headerlink" title="Solve"></a>Solve</h1><h3 id="String"><a href="#String" class="headerlink" title="String"></a>String</h3><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{string}</span> <span class="variable">s</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return <span class="type">{boolean}</span></span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">var</span> isValid = <span class="function"><span class="keyword">function</span>(<span class="params">s</span>) </span>{</span><br><span class="line"> <span class="keyword">let</span> preS = <span class="string">''</span></span><br><span class="line"> <span class="keyword">while</span>(s !== preS){</span><br><span class="line"> preS = s</span><br><span class="line"> s = s.split(<span class="string">'()'</span>).join(<span class="string">''</span>)</span><br><span class="line"> s = s.split(<span class="string">'[]'</span>).join(<span class="string">''</span>)</span><br><span class="line"> s = s.split(<span class="string">'{}'</span>).join(<span class="string">''</span>) </span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(!s)</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">};</span><br></pre></td></tr></table></figure>
<h3 id="Stack"><a href="#Stack" class="headerlink" title="Stack"></a>Stack</h3><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{string}</span> <span class="variable">s</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return <span class="type">{boolean}</span></span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">var</span> isValid = <span class="function"><span class="keyword">function</span>(<span class="params">s</span>) </span>{</span><br><span class="line"> <span class="keyword">const</span> stack = []</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">let</span> i = <span class="number">0</span>; i < s.length; i++){</span><br><span class="line"> <span class="keyword">let</span> c = s.charAt(i);</span><br><span class="line"> <span class="keyword">switch</span>(c){</span><br><span class="line"> <span class="keyword">case</span> <span class="string">'('</span>:</span><br><span class="line"> stack.push(<span class="string">')'</span>);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">'{'</span>:</span><br><span class="line"> stack.push(<span class="string">'}'</span>);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">'['</span>:</span><br><span class="line"> stack.push(<span class="string">']'</span>);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">default</span>:</span><br><span class="line"> <span class="keyword">if</span>(c !== stack.pop()){</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> stack.length === <span class="number">0</span></span><br><span class="line">};</span><br></pre></td></tr></table></figure>
<blockquote>
<p>Runtime: 88 ms, faster than 21.46% of JavaScript online submissions for Valid Parentheses.<br>Memory Usage: 33.1 MB, less than 99.01% of JavaScript online submissions for Valid Parentheses.</p>
</blockquote>
]]></content>
<categories>
<category>LeetCode刷题</category>
</categories>
</entry>
<entry>
<title>LeetCode|String|12. Integer to Roman</title>
<url>/2020/07/17/LeetCode%7CString%7C12.%20Integer%20to%20Roman/</url>
<content><![CDATA[<h1 id="Problem"><a href="#Problem" class="headerlink" title="Problem "></a><a href="https://leetcode.com/problems/integer-to-roman/" target="_blank" rel="noopener">Problem </a></h1><p>Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.</p>
<table>
<thead>
<tr>
<th>Symbol</th>
<th>Value</th>
</tr>
</thead>
<tbody><tr>
<td>I</td>
<td>1</td>
</tr>
<tr>
<td>V</td>
<td>5</td>
</tr>
<tr>
<td>X</td>
<td>10</td>
</tr>
<tr>
<td>L</td>
<td>50</td>
</tr>
<tr>
<td>C</td>
<td>100</td>
</tr>
<tr>
<td>D</td>
<td>500</td>
</tr>
<tr>
<td>M</td>
<td>1000</td>
</tr>
</tbody></table>
<p>For example, two is written as II in Roman numeral, just two one’s added together. Twelve is written as, XII, which is simply X + II. The number twenty seven is written as XXVII, which is XX + V + II.</p>
<p>Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:</p>
<p>I can be placed before V (5) and X (10) to make 4 and 9.<br>X can be placed before L (50) and C (100) to make 40 and 90.<br>C can be placed before D (500) and M (1000) to make 400 and 900.<br>Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.</p>
<p>Example 1:</p>
<blockquote>
<p>Input: 3<br>Output: “III”</p>
</blockquote>
<p>Example 2:</p>
<blockquote>
<p>Input: 4<br>Output: “IV”</p>
</blockquote>
<p>Example 3:</p>
<blockquote>
<p>Input: 9<br>Output: “IX”</p>
</blockquote>
<p>Example 4:</p>
<blockquote>
<p>Input: 58<br>Output: “LVIII”<br>Explanation: L = 50, V = 5, III = 3.</p>
</blockquote>
<p>Example 5:</p>
<blockquote>
<p>Input: 1994<br>Output: “MCMXCIV”<br>Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.</p>
</blockquote>
<h1 id="Solve"><a href="#Solve" class="headerlink" title="Solve"></a>Solve</h1><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{number}</span> <span class="variable">num</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return <span class="type">{string}</span></span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">var</span> intToRoman = <span class="function"><span class="keyword">function</span>(<span class="params">num</span>) </span>{</span><br><span class="line"> <span class="keyword">var</span> stringArr = [];</span><br><span class="line"> <span class="keyword">var</span> i = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">var</span> a = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">var</span> b = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">while</span>(num >= <span class="number">1</span>){</span><br><span class="line"> b = <span class="built_in">Math</span>.floor(num % <span class="number">10</span>);</span><br><span class="line"> <span class="keyword">if</span>(b < <span class="number">4</span>){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">let</span> j = <span class="number">0</span>; j < b; j ++)</span><br><span class="line"> stringArr.push(symbol[i]);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>(b === <span class="number">4</span>){<span class="comment">// VI -> IV</span></span><br><span class="line"> stringArr.push(symbol[i+<span class="number">1</span>]);</span><br><span class="line"> stringArr.push(symbol[i]);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>(b === <span class="number">5</span>){</span><br><span class="line"> stringArr.push(symbol[i+<span class="number">1</span>]);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>(b < <span class="number">9</span>){<span class="comment">// IIIX -> XIII</span></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">let</span> j = <span class="number">5</span>; j < b; j ++)</span><br><span class="line"> stringArr.push(symbol[i]);</span><br><span class="line"> stringArr.push(symbol[i+<span class="number">1</span>]);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>(b === <span class="number">9</span>){<span class="comment">// b = 9 XI -> IX</span></span><br><span class="line"> stringArr.push(symbol[i+<span class="number">2</span>]);</span><br><span class="line"> stringArr.push(symbol[i]);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> i += <span class="number">2</span>;</span><br><span class="line"> num = <span class="built_in">Math</span>.floor(num/<span class="number">10</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> stringArr.reverse().join(<span class="string">''</span>);</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> symbol =[<span class="string">"I"</span>,<span class="string">"V"</span>,<span class="string">"X"</span>,<span class="string">"L"</span>,<span class="string">"C"</span>, <span class="string">"D"</span>,<span class="string">"M"</span>]</span><br></pre></td></tr></table></figure>
]]></content>
<categories>
<category>LeetCode刷题</category>
</categories>
</entry>
<entry>
<title>LeetCode|String|937. Reorder Data in Log Files</title>
<url>/2020/07/17/LeetCode%7CString%7C937._Reorder%20Data%20in%20Log%20Files/</url>
<content><![CDATA[<h1 id="Problem"><a href="#Problem" class="headerlink" title="Problem"></a>Problem</h1><p>You have an array of logs. Each log is a space delimited string of words.</p>
<p>For each log, the first word in each log is an alphanumeric identifier. Then, either:</p>
<p>Each word after the identifier will consist only of lowercase letters, or;<br>Each word after the identifier will consist only of digits.<br>We will call these two varieties of logs letter-logs and digit-logs. It is guaranteed that each log has at least one word after its identifier.</p>
<p>Reorder the logs so that all of the letter-logs come before any digit-log. The letter-logs are ordered lexicographically ignoring identifier, with the identifier used in case of ties. The digit-logs should be put in their original order.</p>
<p>Return the final order of the logs.</p>
<blockquote>
<p>Example 1:</p>
<p>Input: logs = [“dig1 8 1 5 1”,”let1 art can”,”dig2 3 6”,”let2 own kit dig”,”let3 art zero”]<br>Output: [“let1 art can”,”let3 art zero”,”let2 own kit dig”,”dig1 8 1 5 1”,”dig2 3 6”]</p>
</blockquote>
<p>Constraints:</p>
<blockquote>
<p>0 <= logs.length <= 100<br>3 <= logs[i].length <= 100<br>logs[i] is guaranteed to have an identifier, and a word after the identifier.</p>
</blockquote>
<h1 id="Solve"><a href="#Solve" class="headerlink" title="Solve"></a>Solve</h1><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> reorderLogFiles = <span class="function"><span class="keyword">function</span>(<span class="params">logs</span>) </span>{</span><br><span class="line"> <span class="keyword">let</span> letters = [];</span><br><span class="line"> <span class="keyword">let</span> digits = [];</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span>; i < logs.length; i++) {</span><br><span class="line"> <span class="keyword">if</span> (<span class="built_in">isFinite</span>(logs[i].split(<span class="string">' '</span>)[<span class="number">1</span>])) {</span><br><span class="line"> digits.push(logs[i]);</span><br><span class="line"> } <span class="keyword">else</span> letters.push(logs[i]);</span><br><span class="line"> } </span><br><span class="line"> </span><br><span class="line"> letters.sort(<span class="function">(<span class="params">a,b</span>) =></span> {</span><br><span class="line"> <span class="keyword">let</span> aCut = a.slice(a.indexOf(<span class="string">' '</span>) + <span class="number">1</span>);</span><br><span class="line"> <span class="keyword">let</span> bCut = b.slice(b.indexOf(<span class="string">' '</span>) + <span class="number">1</span>);</span><br><span class="line"> <span class="keyword">if</span> (aCut === bCut) {</span><br><span class="line"> <span class="keyword">return</span> a > b ? <span class="number">1</span> : <span class="number">-1</span>;</span><br><span class="line"> } <span class="keyword">else</span> <span class="keyword">return</span> aCut > bCut ? <span class="number">1</span> : <span class="number">-1</span>; </span><br><span class="line"> });</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">return</span> [...letters, ...digits]</span><br><span class="line">};</span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> reorderLogFiles = <span class="function"><span class="keyword">function</span>(<span class="params">logs</span>) </span>{</span><br><span class="line"> <span class="comment">// String to array</span></span><br><span class="line"> <span class="keyword">const</span> body = <span class="function"><span class="params">s</span> =></span> s.slice(s.indexOf(<span class="string">' '</span>) + <span class="number">1</span>) ;</span><br><span class="line"> <span class="comment">// Boolean </span></span><br><span class="line"> <span class="keyword">const</span> isNum = <span class="function"><span class="params">c</span> =></span> <span class="regexp">/\d/</span>.test(c);</span><br><span class="line"> </span><br><span class="line"> <span class="comment">//compare id</span></span><br><span class="line"> <span class="keyword">const</span> compare = <span class="function">(<span class="params">a, b</span>) =></span> {</span><br><span class="line"> <span class="keyword">const</span> n = body(a).localeCompare(body(b));</span><br><span class="line"> <span class="keyword">if</span>(n !== <span class="number">0</span>)</span><br><span class="line"> <span class="keyword">return</span> n;</span><br><span class="line"> <span class="keyword">return</span> a.localeCompare(b);</span><br><span class="line"> };</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">const</span> digitLogs = [];</span><br><span class="line"> <span class="keyword">const</span> letterLogs = [];</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">for</span>( <span class="keyword">const</span> log <span class="keyword">of</span> logs){</span><br><span class="line"> <span class="keyword">if</span> (isNum(body(log))) digitLogs.push(log);</span><br><span class="line"> <span class="keyword">else</span> letterLogs.push(log);</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">return</span> [...letterLogs.sort(compare), ...digitLogs];</span><br><span class="line"> </span><br><span class="line">};</span><br></pre></td></tr></table></figure>
]]></content>
<categories>
<category>LeetCode刷题</category>
</categories>
</entry>
<entry>
<title>LeetCode|String|344. Reverse String</title>
<url>/2020/07/17/LeetCode%7CString%7C344.%20Reverse%20String/</url>
<content><![CDATA[<h1 id="Problem"><a href="#Problem" class="headerlink" title="Problem"></a>Problem</h1><p>Write a function that reverses a string. The input string is given as an array of characters char[].</p>
<p>Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.</p>
<p>You may assume all the characters consist of printable ascii characters.</p>
<p>Example 1:</p>
<blockquote>
<p>Input: [“h”,”e”,”l”,”l”,”o”]<br>Output: [“o”,”l”,”l”,”e”,”h”]</p>
</blockquote>
<p>Example 2:</p>
<blockquote>
<p>Input: [“H”,”a”,”n”,”n”,”a”,”h”]<br>Output: [“h”,”a”,”n”,”n”,”a”,”H”]</p>
</blockquote>
<h1 id="Solve"><a href="#Solve" class="headerlink" title="Solve"></a>Solve</h1><p>String 最后一位是 undefined</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{character[]}</span> <span class="variable">s</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return <span class="type">{void}</span> </span>Do not return anything, modify s in-place instead.</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">var</span> reverseString = <span class="function"><span class="keyword">function</span>(<span class="params">s</span>) </span>{</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">let</span> i = <span class="number">0</span>; i < s.length/<span class="number">2</span>; i++){</span><br><span class="line"> <span class="keyword">var</span> temp = s[i];</span><br><span class="line"> s[i] = s[s.length - i <span class="number">-1</span>]</span><br><span class="line"> s[s.length - i <span class="number">-1</span>] = temp</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> s;</span><br><span class="line">};</span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category>LeetCode刷题</category>
</categories>
</entry>
<entry>
<title>LeetCode|String|Backtrack|22. Generate Parentheses</title>
<url>/2020/07/17/LeetCode%7CString%7CBacktrack%7C22.%20Generate%20Parentheses/</url>
<content><![CDATA[<h1 id="Problem"><a href="#Problem" class="headerlink" title="Problem"></a>Problem</h1><p>Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.</p>
<p>For example, given n = 3, a solution set is:</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">[</span><br><span class="line"> "((()))",</span><br><span class="line"> "(()())",</span><br><span class="line"> "(())()",</span><br><span class="line"> "()(())",</span><br><span class="line"> "()()()"</span><br><span class="line">]</span><br></pre></td></tr></table></figure>
<h1 id="Solve"><a href="#Solve" class="headerlink" title="Solve"></a>Solve</h1><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{number}</span> <span class="variable">n</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return <span class="type">{string[]}</span></span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">var</span> generateParenthesis = <span class="function"><span class="keyword">function</span>(<span class="params">n</span>) </span>{</span><br><span class="line"> <span class="keyword">let</span> res = []</span><br><span class="line"> </span><br><span class="line"> <span class="function"><span class="keyword">function</span> <span class="title">go</span>(<span class="params">left, right, str</span>)</span>{</span><br><span class="line"> <span class="keyword">if</span>(left > right)</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">if</span>(left ===<span class="number">0</span> && right ===<span class="number">0</span>){</span><br><span class="line"> res.push(str);</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">if</span>(left > <span class="number">0</span>)</span><br><span class="line"> go(left<span class="number">-1</span>, right, str + <span class="string">'('</span>);</span><br><span class="line"> <span class="keyword">if</span>(right > <span class="number">0</span>)</span><br><span class="line"> go(left, right<span class="number">-1</span>, str + <span class="string">')'</span>);</span><br><span class="line"> }</span><br><span class="line"> go(n,n,<span class="string">''</span>)</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">return</span> res;</span><br><span class="line">};</span><br></pre></td></tr></table></figure>]]></content>
<categories>
<category>LeetCode刷题</category>
<category>Backtracking</category>
</categories>
</entry>
<entry>
<title>LeetCode|24 Swap Node In Pairs</title>
<url>/2020/07/14/LeetCode%7CTwoPointer%7C24_SwapNodeInPairs/</url>
<content><![CDATA[<h1 id="Problem"><a href="#Problem" class="headerlink" title="Problem"></a>Problem</h1><p>Given a linked list, swap every two adjacent nodes and return its head.</p>
<p>You may not modify the values in the list’s nodes, only nodes itself may be changed.</p>
<p>Example:</p>
<blockquote>
<p>Given 1->2->3->4, you should return the list as 2->1->4->3.</p>
</blockquote>
<h1 id="Sovle"><a href="#Sovle" class="headerlink" title="Sovle"></a>Sovle</h1><h3 id="Link-Table"><a href="#Link-Table" class="headerlink" title="Link Table"></a>Link Table</h3><p>这题本意比较简单,1 -> 2 -> 3 -> 4 的情况下可以定义一个递归的辅助函数 helper,这个辅助函数对于节点和它的下一个节点进行交换,比如 helper(1) 处理 1 -> 2,并且把交换变成 2 -> 1 的尾节点 1的next继续指向 helper(3)也就是交换后的 4 -> 3。</p>
<p>边界情况在于,如果顺利的作了两两交换,那么交换后我们的函数返回出去的是 交换后的头部节点,但是如果是奇数剩余项的情况下,没办法做交换,那就需要直接返回 原本的头部节点。这个在 helper函数和主函数中都有体现。</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * Definition for singly-linked list.</span></span><br><span class="line"><span class="comment"> * function ListNode(val, next) {</span></span><br><span class="line"><span class="comment"> * this.val = (val===undefined ? 0 : val)</span></span><br><span class="line"><span class="comment"> * this.next = (next===undefined ? null : next)</span></span><br><span class="line"><span class="comment"> * }</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{ListNode}</span> <span class="variable">head</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return <span class="type">{ListNode}</span></span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">var</span> swapPairs = <span class="function"><span class="keyword">function</span>(<span class="params">head</span>) </span>{</span><br><span class="line"> <span class="keyword">if</span>(!head){</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">let</span> helper = <span class="function"><span class="keyword">function</span> (<span class="params">node</span>) </span>{</span><br><span class="line"> <span class="keyword">let</span> tempNext = node.next;</span><br><span class="line"> <span class="keyword">if</span>(tempNext){</span><br><span class="line"> <span class="keyword">let</span> tempNextNext = node.next.next; <span class="comment">//1 --> 3--></span></span><br><span class="line"> <span class="comment">//swap 1-> 2 to 2->1</span></span><br><span class="line"> node.next.next = node;</span><br><span class="line"> <span class="comment">//2 -> 1 ---></span></span><br><span class="line"> node.next = tempNextNext ? helper(tempNextNext) : <span class="literal">null</span>;</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">return</span> tempNext || node;</span><br><span class="line"> }</span><br><span class="line"> };</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">let</span> res =helper(head);</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">return</span> res || head;</span><br><span class="line">};</span><br></pre></td></tr></table></figure>
]]></content>
<categories>
<category>LeetCode刷题</category>
<category>TwoPointer</category>
</categories>
<tags>
<tag>TwoPointer</tag>
<tag>LeetCode</tag>
</tags>
</entry>
<entry>
<title>LeetCode|String|Backtrack|2. Add Two Numbers</title>
<url>/2020/07/17/LeetCode%7CString%7CBacktrack%7C2.%20Add%20Two%20Numbers/</url>
<content><![CDATA[<h1 id="Problem"><a href="#Problem" class="headerlink" title="Problem"></a><a href="https://leetcode.com/problems/add-two-numbers/" target="_blank" rel="noopener">Problem</a></h1><p>You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.</p>
<p>You may assume the two numbers do not contain any leading zero, except the number 0 itself.</p>
<p>Example:</p>
<blockquote>
<p>Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)<br>Output: 7 -> 0 -> 8<br>Explanation: 342 + 465 = 807.</p>
</blockquote>
<h1 id="Solve"><a href="#Solve" class="headerlink" title="Solve"></a>Solve</h1><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * Definition for singly-linked list.</span></span><br><span class="line"><span class="comment"> * function ListNode(val, next) {</span></span><br><span class="line"><span class="comment"> * this.val = (val===undefined ? 0 : val)</span></span><br><span class="line"><span class="comment"> * this.next = (next===undefined ? null : next)</span></span><br><span class="line"><span class="comment"> * }</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{ListNode}</span> <span class="variable">l1</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{ListNode}</span> <span class="variable">l2</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return <span class="type">{ListNode}</span></span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">var</span> addTwoNumbers = <span class="function"><span class="keyword">function</span>(<span class="params">l1, l2</span>) </span>{</span><br><span class="line"> <span class="keyword">const</span> head = <span class="keyword">new</span> ListNode();</span><br><span class="line"> <span class="keyword">let</span> cursor = head;</span><br><span class="line"> <span class="keyword">let</span> carry = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">while</span> (l1 || l2 || carry) {</span><br><span class="line"> cursor.next = <span class="keyword">new</span> ListNode();</span><br><span class="line"> cursor = cursor.next;</span><br><span class="line"> <span class="keyword">let</span> val = (l1 ? l1.val : <span class="number">0</span>) + (l2 ? l2.val : <span class="number">0</span>) + carry;</span><br><span class="line"> carry = val >= <span class="number">10</span> ? <span class="number">1</span> : <span class="number">0</span>;</span><br><span class="line"> cursor.val = val % <span class="number">10</span>;</span><br><span class="line"> l1 = l1 ? l1.next : <span class="literal">null</span>;</span><br><span class="line"> l2 = l2 ? l2.next : <span class="literal">null</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> head.next;</span><br><span class="line">};</span><br></pre></td></tr></table></figure>
<h3 id="self"><a href="#self" class="headerlink" title="self"></a>self</h3><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> addTwoNumbers = <span class="function"><span class="keyword">function</span>(<span class="params">l1, l2</span>) </span>{</span><br><span class="line"> <span class="keyword">let</span> res = <span class="keyword">new</span> ListNode(<span class="number">-1</span>), dummy = res, sum = <span class="number">0</span>,carry = <span class="number">0</span>;</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">if</span>(!l1 || !l2){</span><br><span class="line"> <span class="keyword">return</span> l1 || l2;</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">while</span>(l1 || l2 || sum> <span class="number">0</span>){</span><br><span class="line"> <span class="keyword">if</span>(l1){</span><br><span class="line"> sum += l1.val;</span><br><span class="line"> l1 = l1.next;</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">if</span>(l2){</span><br><span class="line"> sum += l2.val;</span><br><span class="line"> l2 = l2.next;</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">if</span>(sum >= <span class="number">10</span>){</span><br><span class="line"> sum -= <span class="number">10</span>;</span><br><span class="line"> carry = <span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> dummy.next = <span class="keyword">new</span> ListNode(sum);</span><br><span class="line"> dummy = dummy.next;</span><br><span class="line"> sum = carry;</span><br><span class="line"> carry = <span class="number">0</span>;</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">return</span> res.next;</span><br><span class="line">};</span><br></pre></td></tr></table></figure>
]]></content>
<categories>
<category>LeetCode刷题</category>
</categories>
</entry>
<entry>
<title>LeetCode|String|Backtracking|17. Letter Combinations of a Phone Number</title>
<url>/2020/07/17/LeetCode%7CString%7CBacktracking%7C17.%20Letter%20Combinations%20of%20a%20Phone%20Number/</url>
<content><![CDATA[<h1 id="Problem"><a href="#Problem" class="headerlink" title="Problem "></a><a href="https://leetcode.com/problems/trapping-rain-water/" target="_blank" rel="noopener">Problem </a></h1><p>Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.</p>
<p>A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> map = {</span><br><span class="line"> <span class="number">2</span> : <span class="string">"abc"</span>,</span><br><span class="line"> <span class="number">3</span> : <span class="string">"def"</span>,</span><br><span class="line"> <span class="number">4</span> : <span class="string">"ghi"</span>,</span><br><span class="line"> <span class="number">5</span> : <span class="string">"jkl"</span>,</span><br><span class="line"> <span class="number">6</span> : <span class="string">"mno"</span>,</span><br><span class="line"> <span class="number">7</span> : <span class="string">"pqrs"</span>,</span><br><span class="line"> <span class="number">8</span> : <span class="string">"tuv"</span>,</span><br><span class="line"> <span class="number">9</span> : <span class="string">"wxyz"</span>,</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>Example:</p>
<p>Input: “23”<br>Output: [“ad”, “ae”, “af”, “bd”, “be”, “bf”, “cd”, “ce”, “cf”].</p>
<h1 id="Solve"><a href="#Solve" class="headerlink" title="Solve"></a>Solve</h1><p>回溯方法:</p>
<ol>
<li>遍历+ 字符串返回</li>
<li>字符串返回遍历:char遍历 利用map</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{string}</span> <span class="variable">digits</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return <span class="type">{string[]}</span></span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">var</span> letterCombinations = <span class="function"><span class="keyword">function</span>(<span class="params">digits</span>) </span>{</span><br><span class="line"> <span class="keyword">let</span> res = [];</span><br><span class="line"> <span class="keyword">let</span> len = digits.length;</span><br><span class="line"> <span class="keyword">if</span>(len === <span class="number">0</span>)</span><br><span class="line"> <span class="keyword">return</span> res;</span><br><span class="line"> </span><br><span class="line"> <span class="function"><span class="keyword">function</span> <span class="title">go</span>(<span class="params">n, str</span>)</span>{</span><br><span class="line"> <span class="keyword">if</span>(n === len){</span><br><span class="line"> res.push(str);</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">let</span> char <span class="keyword">of</span> map[digits[n]]){</span><br><span class="line"> go(n + <span class="number">1</span> ,str + char);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> go(<span class="number">0</span>, <span class="string">''</span>);</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">return</span> res;</span><br><span class="line"> </span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> map = {</span><br><span class="line"> <span class="number">2</span>:<span class="string">"abc"</span>,</span><br><span class="line"> <span class="number">3</span>:<span class="string">"def"</span>,</span><br><span class="line"> <span class="number">4</span>:<span class="string">"ghi"</span>,</span><br><span class="line"> <span class="number">5</span>:<span class="string">"jkl"</span>,</span><br><span class="line"> <span class="number">6</span>:<span class="string">"mno"</span>,</span><br><span class="line"> <span class="number">7</span>:<span class="string">"pqrs"</span>,</span><br><span class="line"> <span class="number">8</span>:<span class="string">"tuv"</span>,</span><br><span class="line"> <span class="number">9</span>:<span class="string">"wxyz"</span>,</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
]]></content>
<categories>
<category>LeetCode刷题</category>
</categories>
</entry>
<entry>
<title>LeetCode|Two_Pointer|16 3Sum Closet</title>
<url>/2020/07/14/LeetCode%7CTwo_Pointer%7C16-3Sum_Closet/</url>
<content><![CDATA[<h1 id="题目"><a href="#题目" class="headerlink" title="题目"></a>题目</h1><p>16—<a href="https://leetcode.com/problems/3sum-closest/" target="_blank" rel="noopener">3Sum Closest</a><br>Medium</p>
<p>Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution.</p>
<p>Example 1:</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">Input: nums = [-1,2,1,-4], target = 1</span><br><span class="line">Output: 2</span><br><span class="line">Explanation: The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).</span><br></pre></td></tr></table></figure>
<p>Constraints:</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">3 <= nums.length <= 10^3</span><br><span class="line">-10^3 <= nums[i] <= 10^3</span><br><span class="line">-10^4 <= target <= 10^4</span><br></pre></td></tr></table></figure>
<h1 id="解题"><a href="#解题" class="headerlink" title="解题"></a>解题</h1><h3 id="双指针"><a href="#双指针" class="headerlink" title="双指针"></a>双指针</h3><p>先按照升序排序,然后分别从左往右依次选择一个基础点 i(0 <= i <= nums.length - 3),在基础点的右侧用双指针去不断的找最小的差值。</p>
<p>假设基础点是 i,初始化的时候,双指针分别是:</p>
<p>left:i + 1,基础点右边一位。<br>right: nums.length - 1 数组最后一位。<br>然后求此时的和,如果和大于 target,那么可以把右指针左移一位,去试试更小一点的值,反之则把左指针右移。</p>
<p>在这个过程中,不断更新全局的最小差值 min,和此时记录下来的和 res。</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{number[]}</span> <span class="variable">nums</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">{number}</span> <span class="variable">target</span></span></span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return <span class="type">{number}</span></span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">var</span> threeSumClosest = <span class="function"><span class="keyword">function</span>(<span class="params">nums, target</span>) </span>{</span><br><span class="line"> <span class="keyword">let</span> len = nums.length;</span><br><span class="line"> <span class="keyword">if</span>(len === <span class="number">3</span>){</span><br><span class="line"> <span class="keyword">return</span> getSum(nums);</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> nums.sort(<span class="function">(<span class="params">a,b</span>)=></span> a-b);</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">let</span> min = <span class="literal">Infinity</span>;</span><br><span class="line"> <span class="keyword">let</span> res;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">let</span> i = <span class="number">0</span>; i < len - <span class="number">2</span>; i++){</span><br><span class="line"> <span class="keyword">let</span> basic = nums[i];</span><br><span class="line"> <span class="keyword">let</span> left = i + <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">let</span> right = len - <span class="number">1</span>;</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">while</span>(left < right){</span><br><span class="line"> <span class="keyword">let</span> sum = basic + nums[left] + nums[right];</span><br><span class="line"> <span class="keyword">let</span> diff = <span class="built_in">Math</span>.abs(sum - target);</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">if</span>(diff < min){</span><br><span class="line"> min = diff;</span><br><span class="line"> res = sum;</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">if</span>(sum < target){</span><br><span class="line"> left ++;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>( sum > target){</span><br><span class="line"> right --;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">return</span> sum;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">return</span> res;</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getSum</span>(<span class="params">nums</span>)</span>{</span><br><span class="line"> <span class="keyword">return</span> nums.reduce(<span class="function">(<span class="params">total, cur</span>)=></span> total + cur, <span class="number">0</span>)</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h3 id="来源"><a href="#来源" class="headerlink" title="来源"></a>来源</h3><p><a href="https://mp.weixin.qq.com/s/7mJSpnHE319swy0LStpavQ" target="_blank" rel="noopener">双指针问题</a></p>
]]></content>
<categories>
<category>LeetCode刷题</category>
<category>Two_Pointer</category>
</categories>
</entry>
<entry>
<title>后端|java面试</title>
<url>/2020/07/13/java%E9%9D%A2%E8%AF%95/</url>
<content><![CDATA[<ul>
<li>Java 基础</li>
<li>容器</li>
<li>多线程</li>
<li>反射</li>
<li>对象拷贝</li>
<li>java Web 模块</li>
<li>异常</li>
<li>网络</li>
<li>设计模式</li>
<li>Spring/Spring MVC</li>
<li>Spring Boot/Spring Cloud</li>
<li>Hibernate</li>
<li>Mybatis</li>
<li>RabbitMQ</li>
<li>Kafka</li>
<li>Zookeeper</li>
<li>MySql</li>
<li>Redis</li>
<li>JVM </li>
</ul>
]]></content>
<categories>
<category>后端</category>
<category>java</category>
</categories>
<tags>
<tag>后端</tag>
<tag>java</tag>
</tags>
</entry>
<entry>
<title>前端|React|Redux</title>
<url>/2020/07/13/React-Redux-store/</url>
<content><![CDATA[]]></content>
<categories>
<category>javascript</category>
<category>前端</category>
<category>React</category>
<category>Redux</category>
</categories>
<tags>
<tag>前端</tag>
<tag>React</tag>
<tag>javascript</tag>
<tag>Redux</tag>
</tags>
</entry>
<entry>
<title>前端|Vue 杂七杂八</title>
<url>/2020/07/13/Vue-%E6%9D%82%E4%B8%83%E6%9D%82%E5%85%AB/</url>
<content><![CDATA[<h1 id="问题:"><a href="#问题:" class="headerlink" title="问题:"></a>问题:</h1><ol>
<li><p>Keep-alive (场景 视频VLog) <a href="https://juejin.im/post/5d92acae6fb9a04e143daa0c" target="_blank" rel="noopener"> 文章</a></p>
<ol>
<li>作用:缓存 - 降级荣塞</li>
<li>How: 以队列方式缓存</li>
<li>缓存的是什么:VNode (虚拟DOM)</li>
<li>坑:内存泄漏 解决方法:缓存数量限制<ol start="5">
<li>使用了什么机制: LRU</li>
</ol>
<ul>
<li>显示隐藏</li>
<li>设置缓存大小 </li>
<li>自己写<pre><code>(Keep-alive 缓存的是结果,也就是vnode,如果太大就缓存数据)</code></pre><ul>
<li>有卡顿<ul>
<li></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<p>Vue 基于数据驱动 -> 缓存数据<br>#第一 </p>
<ol>
<li><p>Vue runtime + complier</p>
<ul>
<li><p>运行时生命周期 编译时</p>
<ul>
<li><p>template -></p>
</li>
<li><p>(上线前变异)ast-></p>
<ul>
<li><p>(本地Complier,将<em>.vue打包成js,上线的时候只是JS 上传到服务器)render -></em></p>
<ul>
<li><p>【运行时】<strong>vnode (内存中存在的状态)在内存中diff</strong>-></p>
<blockquote>
<pre><code>DOM PULL 在React,主动发出的动作(react setSate props)后数据发生改变
DOM PUSH 在Vue,通过响应数据生成DOM </code></pre><p><code><div></div>. 一个组建-> 一个watcher[内存]-> DOM</code><br>组建内部用Diff修改<br>为什么有Vnode/虚拟DOM: (缓存:类似 寄存器/内存/硬盘) 虚拟DOM - 缓冲地带 - 不同端运行</p>
</blockquote>
<p>在线编译:浏览器JS运行时候调用template,然后解析<br>RuntimeOnly:如果要在Template里面加入<strong>Component后性能非常差,必须要加入Complier包</strong>,优化成render函数然后删除这个包(资源优化)。 </p>
<ul>
<li>(通过patch(){ doucument.getElementBy(‘’).apendchild()})<strong>修改正式DOM的动作,通过虚拟DOM树递归【慢】, react中做了fiber,做时间分片</strong> <a href="https://juejin.im/post/5dadc6045188255a270a0f85" target="_blank" rel="noopener">React Fiber(时间分片)</a><ul>
<li>-> 转换成DOM</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><p>script(浏览器从服务器拉下js开始运行) –> </p>
</li>
<li><p>new Vue() -> (把数据处理成)响应data <strong>(生成vnode)</strong></p>
</li>
<li><p>style</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p>Vue 浏览器端一贞解析机制</p>
</li>
<li><p>Vue 首屏优化</p>
<ul>
<li>优化<ul>
<li>如何优化加载速度,白屏如何引起的<ul>
<li>运行环境:</li>
<li>浏览器如何渲染:js/css/html </li>
<li>来源 - <a href="https://aerotwist.com/blog/the-anatomy-of-a-frame/" target="_blank" rel="noopener">浏览器一帧渲染</a>: </li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ol>
</li>
</ol>
]]></content>
<categories>
<category>Vue</category>
<category>前端</category>
<category>javascript</category>
</categories>
<tags>
<tag>前端</tag>
<tag>javascript</tag>
<tag>Vue</tag>
</tags>
</entry>
<entry>
<title>前端|安全|防止sql注入</title>
<url>/2020/07/13/%E5%AE%89%E5%85%A8%E2%80%94javascript-%E9%98%B2%E6%AD%A2%E4%BE%9D%E8%B5%96%E6%B3%A8%E5%85%A5/</url>
<content><![CDATA[<p>SQL注入攻击的总体思路</p>
<ul>
<li>寻找到SQL注入的位置</li>
<li>判断服务器类型和后台数据库类型</li>
<li>针对不通的服务器和数据库特点进行SQL注入攻击</li>
</ul>
<p>#各种语言如何防止</p>
<ol>
<li><p>javascript</p>
<ol>
<li><p>URL 地址防止注入:</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">//过滤URL非法SQL字符</span></span><br><span class="line"> <span class="keyword">var</span> sUrl=location.search.toLowerCase();</span><br><span class="line"> <span class="keyword">var</span> sQuery=sUrl.substring(sUrl.indexOf(<span class="string">"="</span>)+<span class="number">1</span>);</span><br><span class="line"> re=<span class="regexp">/select|update|delete|truncate|join|union|exec|insert|drop|count|'|"|;|>|<|%/i</span>;</span><br><span class="line"> <span class="keyword">if</span>(re.test(sQuery))</span><br><span class="line"> {</span><br><span class="line"> alert(<span class="string">"请勿输入非法字符"</span>); </span><br><span class="line"> location.href=sUrl.replace(sQuery,<span class="string">""</span>);</span><br><span class="line"> }</span><br></pre></td></tr></table></figure>
</li>
<li><p>输入文本框防注入 </p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">AntiSqlValid</span>(<span class="params">oField </span>)</span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> re= <span class="regexp">/select|update|delete|exec|count|'|"|=|;|>|<|%/i</span>;</span><br><span class="line"> <span class="keyword">if</span> ( re.test(oField.value) )</span><br><span class="line"> {</span><br><span class="line"> <span class="comment">//alert("请您不要在参数中输入特殊字符和SQL关键字!"); //注意中文乱码</span></span><br><span class="line"> oField.value = <span class="string">";</span></span><br><span class="line"><span class="string"> oField.className="</span>errInfo<span class="string">";</span></span><br><span class="line"><span class="string"> oField.focus();</span></span><br><span class="line"><span class="string"> return false;</span></span><br><span class="line"><span class="string"> }</span></span><br><span class="line"><span class="string"> ...</span></span><br><span class="line"><span class="string">}</span></span><br><span class="line"><span class="string">//在需要防注入的输入文本框添加如下方法</span></span><br><span class="line"><span class="string">txtName.Attributes.Add("</span>onblur<span class="string">", "</span>AntiSqlValid(<span class="keyword">this</span>)<span class="string">");//防止Sql脚本注入</span></span><br></pre></td></tr></table></figure>
</li>
</ol>
</li>
<li><p>node</p>
<ol>
<li>node-mysql </li>
</ol>
</li>
<li><p>Php</p>
<ol>
<li>Prepared Statements <ul>
<li>采用预编译语句集,它内置了处理SQL注入的能力,只要使用它的setXXX方法传值即可。 </li>
</ul>
</li>
</ol>
</li>
</ol>
]]></content>
<categories>
<category>安全</category>
<category>前端</category>
<category>javascript</category>
</categories>
<tags>
<tag>前端</tag>
<tag>javascript</tag>
<tag>安全</tag>
</tags>
</entry>
<entry>
<title>中间件策略</title>
<url>/2020/07/18/%E4%B8%AD%E9%97%B4%E4%BB%B6%E7%AD%96%E7%95%A5/</url>
<content><![CDATA[<p>中间件策略</p>
<h1 id="来源"><a href="#来源" class="headerlink" title="来源"></a>来源</h1><ul>
<li><a href="http://jm.taobao.org/archives/page/46/" target="_blank" rel="noopener">淘宝中间件博客</a></li>
</ul>
]]></content>
<categories>
<category>中间件</category>
<category>资源</category>
<category>阿里</category>
</categories>
</entry>
<entry>
<title>前端|视频 |延迟分析</title>
<url>/2020/07/13/RTMP%20%E5%BB%B6%E8%BF%9F%E5%88%86%E6%9E%90/</url>
<content><![CDATA[<p>#RTMP<br>RTMP是Real Time Messaging Protocol(实时消息传输协议)的首字母缩写。该协议基于TCP,是一个协议族,包括RTMP基本协议及RTMPT/RTMPS/RTMPE等多种变种。</p>
<p>RTMP是一种设计用来进行实时数据通信的网络协议,主要用来在Flash/AIR平台和支持RTMP协议的流媒体/交互服务器之间进行音视频和数据通信。支持该协议的软件包括Adobe Media Server/Ultrant Media Server/red5等。</p>
<ul>
<li>RTMP工作在TCP之上,默认使用端口1935;</li>
<li>RTMPE在RTMP的基础上增加了加密功能;</li>
<li>RTMPT封装在HTTP请求之上,可穿透防火墙;</li>
<li>RTMPS类似RTMPT,增加了TLS/SSL的安全功能。</li>
</ul>
<p><a href="https://www.jianshu.com/p/5ce11c20a9df" target="_blank" rel="noopener">来自</a></p>
<h1 id="RTMP-延迟分析"><a href="#RTMP-延迟分析" class="headerlink" title="RTMP 延迟分析"></a>RTMP 延迟分析</h1><p>RTMP和HLS基本上可以覆盖所有客户端观看</p>
<ul>
<li>HLS主要是延时比较大</li>
<li>RTMP主要优势在于延时低</li>
</ul>
<h1 id="应用场景(Verify)"><a href="#应用场景(Verify)" class="headerlink" title="应用场景(Verify)"></a>应用场景(Verify)</h1><p>低延时应用场景包括:</p>
<ul>
<li><p>互动式直播:譬如2013年大行其道的美女主播,游戏直播等等。</p>
<ul>
<li>各种主播,流媒体分发给用户观看。用户可以文字聊天和主播互动。</li>
</ul>
</li>
<li><p>视频会议:我们要是有同事出差在外地,就用视频会议开内部会议。</p>
<ul>
<li>其实会议1秒延时无所谓,因为人家讲完话后,其他人需要思考。</li>
<li>思考的延时也会在1秒左右。当然如果用视频会议吵架就不行。</li>
</ul>
</li>
<li><p>其他:监控,直播也有些地方需要对延迟有要求。</p>
<ul>
<li>互联网上RTMP协议的延迟基本上能够满足要求。<h1 id="来源"><a href="#来源" class="headerlink" title="来源"></a>来源</h1></li>
</ul>
</li>
</ul>
<ol>
<li><a href="https://draveness.me/whys-the-design-live-streaming-latency/" target="_blank" rel="noopener">为什么流媒体直播的延迟很高</a></li>
<li><a href="https://blog.csdn.net/lcalqf/article/details/52993630" target="_blank" rel="noopener">RTMP 延迟分析</a></li>
<li><a href="https://zhuanlan.zhihu.com/p/73984438" target="_blank" rel="noopener">视频和视频帧:ffmpeg的RTMP推流</a></li>
<li><a href="https://www.jianshu.com/p/c04d810b7562" target="_blank" rel="noopener">视频传输协议详解(RTMP、RTSP、HLS)</a></li>
<li><a href="https://www.jianshu.com/p/5ce11c20a9df" target="_blank" rel="noopener">RTMP协议解析(一) —— 基本了解</a></li>
<li><a href="https://zhuanlan.zhihu.com/p/27368329" target="_blank" rel="noopener">流媒体系统的RTMP协议</a></li>
<li><a href="https://blog.csdn.net/dong_beijing/article/details/60776248" target="_blank" rel="noopener">通过信号量和共享内存实现h264码流在不同进程间传输</a></li>
</ol>
]]></content>
<categories>
<category>协议</category>
<category>前端</category>
<category>视频</category>
<category>延迟</category>
</categories>
<tags>
<tag>前端</tag>
<tag>视频</tag>
<tag>延迟</tag>
<tag>协议</tag>
</tags>
</entry>
<entry>
<title>算法|分析大纲</title>
<url>/2020/07/13/%E5%88%86%E7%B1%BB%E5%A4%A7%E7%BA%B2/</url>
<content><![CDATA[<h1 id="分类大纲"><a href="#分类大纲" class="headerlink" title="分类大纲"></a>分类大纲</h1><ul>
<li>算法的复杂度分析</li>
<li>排序算法,以及他们的区别和优化</li>
<li>数组中的双指针、滑动窗口思想</li>
<li>利用 Map 和 Set 处理查找表问题</li>
<li>链表的各种问题</li>
<li>利用递归和迭代法解决二叉树问题</li>
<li>栈、队列、DFS、BFS</li>
<li>回溯法、贪心算法、动态规划</li>
</ul>
<h1 id="图"><a href="#图" class="headerlink" title="图"></a><a href="https://blog.csdn.net/linhuanmars/article/details/39366817" target="_blank" rel="noopener">图</a></h1><p>先来看看最基础的Clone Graph,很简单就是要复制一个图,常见的两种搜索算法(深度和广度)都可以用,具体细节就不在这里解释了,不熟悉的朋友可以看看相关资料。建议大家还是两种都要练一练,因为在解决具体问题中这两种方法还是很常用的。</p>
<p>接下来的这些题都是基于图算法的应用,Word Ladder和Word Ladder II是比较典型的,看起来好像是字符串操作的题目,实际上这里得转换成图的角度来考虑,因为字符集比较小的缘故(26个小写字母),也就是说对于一个单词来说,改变其中一个字符可以有25条边(除去他自己),所以总共有(25*单词的长度L)条边。找到是否有满足一个单词转成另一个单词就是在这个图中找到一条路径。所以我们可以把问题转换成图用广度优先搜索来解决,找到即可停止。</p>
<p>Word Ladder是广度优先搜索的应用,而Longest Consecutive Sequence则是深度优先搜索的应用。题目要求是找出最长的连续整数串,如果把数字看成结点,与它相邻的整数连有边,那么找到最长的连续串就是在这个图中找最长路径。因为是最长路径,这里用深度优先搜索是比较适合的。</p>
<p>Word Search也是一道深度优先搜索的题目,是把上下左右相邻的结点看成有边联结,然后进行深度搜索就可以了,小细节是这里从每个点出发字符就可以重用,所以要重置一下访问结点。</p>
<p>Surrounded Regions要用一个图形学中很常用的填充算法:Flood fill 算法,其实本质还是一个深度优先搜索,跟Word Search一样是把相邻的上下左右看成连边,然后进行搜索填充。</p>
<h1 id="资源"><a href="#资源" class="headerlink" title="资源"></a>资源</h1><p><a href="https://juejin.im/post/5f0b2313e51d45349b5ca747" target="_blank" rel="noopener">前端刷题</a></p>
]]></content>
<categories>
<category>算法</category>
<category>大纲</category>
</categories>
<tags>
<tag>算法</tag>
<tag>大纲</tag>
</tags>
</entry>
<entry>
<title>测试|Google测试</title>
<url>/2020/07/13/%E6%B5%8B%E8%AF%95-google-%E6%B5%8B%E8%AF%95/</url>
<content><![CDATA[<h1 id="Google测试"><a href="#Google测试" class="headerlink" title="Google测试"></a>Google测试</h1><p>##软件测试开发工程师</p>
<ul>
<li>职责:负责可测试性和测试自动化体系的长期有效性。<ul>
<li>扮演<strong>质量顾问</strong>的角色</li>
<li>在<strong>单元测试</strong>方面给予开发人员支持</li>
<li>为开发人员提供<strong>测试框架</strong>,方便开发提高<em><strong><em>测试效率</em></strong></em></li>
<li>参与设计评审、重构代码增加可测试性,编写<strong>单元测试框架</strong>和<strong>自动化测试框架</strong></li>
<li>更加关注于质量提升和<strong>测试覆盖率(code coverage)</strong>的增加,SET写代码的目的是可以让SWE测试自己的功能</li>
</ul>
</li>
</ul>
<p>##测试工程师</p>
<ul>
<li>职责:评估对用户的影响以及软件产品整体目标上的风险<ul>
<li>从用户的角度来思考质量方面各种问题</li>
<li>从开发角度来看,他们编写用户使用场景方面的自动化用例代码</li>
<li>从产品角度来看,他们评估整体测试覆盖度,并验证其他工程师角色在测试方面合作的有效性</li>
<li>产品专家、质量顾问和风险分析师</li>
</ul>
</li>
<li></li>
</ul>
<h1 id="测试工具"><a href="#测试工具" class="headerlink" title="测试工具"></a>测试工具</h1><h2 id="postman"><a href="#postman" class="headerlink" title="postman"></a>postman</h2><ul>
<li><a href="https://www.jianshu.com/p/77f4f9175028" target="_blank" rel="noopener">postman最详细的中文使用教程</a></li>
</ul>
<h2 id="性能测试工具"><a href="#性能测试工具" class="headerlink" title="性能测试工具"></a>性能测试工具</h2><ul>
<li><a href="https://testerhome.com/topics/17068" target="_blank" rel="noopener">wrk,ab,locust,Jmeter 压测结果比较</a></li>
<li><a href="https://zhuanlan.zhihu.com/p/71594831" target="_blank" rel="noopener">记一次使用NodeJS做服务器压力测试</a></li>
<li><a href="https://juejin.im/post/5b827cbbe51d4538c021f2da" target="_blank" rel="noopener">对node工程进行压力测试与性能分析</a></li>
</ul>
]]></content>
<categories>
<category>测试</category>
<category>Google</category>
</categories>
<tags>
<tag>测试</tag>
<tag>Google</tag>
</tags>
</entry>
<entry>
<title>面试|项目介绍</title>
<url>/2020/07/12/%E9%A1%B9%E7%9B%AE%E4%BB%8B%E7%BB%8D/</url>
<content><![CDATA[<h1 id="Baidu"><a href="#Baidu" class="headerlink" title="Baidu"></a>Baidu</h1><h2 id="项目点"><a href="#项目点" class="headerlink" title="项目点"></a>项目点</h2><ul>
<li><p>为什么用这个</p>
</li>
<li><p>替代方案</p>
</li>
<li><p>如何埋点</p>
<ul>
<li><a href="https://tech.meituan.com/2019/08/15/mtflexbox-automation-buried-point-exploration.html" target="_blank" rel="noopener">MTFlexbox自动化埋点探索</a></li>
<li><a href="https://www.cnblogs.com/30go/p/10421507.html" target="_blank" rel="noopener">前端埋点的那些事</a></li>
<li><a href="https://testerhome.com/topics/21321" target="_blank" rel="noopener">埋点自动化测试 Pro</a></li>
<li><a href="https://segmentfault.com/a/1190000014922668" target="_blank" rel="noopener">web 埋点实现原理了解一下</a></li>
<li><a href="https://juejin.im/entry/5d5c00f55188255d3d2997e1" target="_blank" rel="noopener">有赞埋点实践</a></li>
<li><a href="https://www.jianshu.com/p/30f44482ae3b" target="_blank" rel="noopener">FaceBook埋点测试</a></li>
</ul>
</li>
<li><p>QBS</p>
</li>
<li><p>流量缺失了怎么办</p>
</li>
<li><p>并发</p>
</li>
<li><p>代码质量(安全)sql注入</p>
</li>
<li><p>(安全)压力测试 & 测试指标</p>
</li>
<li><p>服务端QPS & 页面呈现fps</p>
</li>
<li><p>读写锁/信号量/管道->并发 /哲学家餐桌 死锁 互斥量 <a href="https://juejin.im/post/5dde2b816fb9a0719b30726c" target="_blank" rel="noopener">Redis 的分布式锁实现</a></p>
<ul>
<li><p>信号量<a href="https://www.jianshu.com/p/c1015f5ffa74" target="_blank" rel="noopener">进程间通信IPC (InterProcess Communication)</a> </p>
</li>
<li><p><a href="https://juejin.im/post/5dde2b816fb9a0719b30726c" target="_blank" rel="noopener">Node.js 中实践基于 Redis 的分布式锁实现</a></p>
</li>
<li><p>安全性:<strong>上了锁。</strong>所谓一个萝卜一个坑,第一点要做的是上锁,在任意时刻要保证仅有一个客户端持有该锁。</p>
<ul>
<li>上锁 <figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">setnx key value </span><br><span class="line"> expire key seconds</span><br></pre></td></tr></table></figure>
<ul>
<li>value:建议设置为一个随机值,在释放锁的时候会进一步讲解</li>
<li>EX seconds:设置的过期时间</li>
<li>PX milliseconds:也是设置过期时间,单位不一样</li>
<li>NX|XX:NX 同 setnx 效果是一样的<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">set key value [EX seconds] [PX milliseconds] [NX|XX]</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
</ul>
</li>
<li><p>释放锁</p>
<ul>
<li><p>加锁的过程中建议把 value 设置为一个随机值,主要是为了更安全的释放锁,在 del key 之前先判断这个 key 存在且 value 等于自己指定的值才执行删除操作。</p>
</li>
<li><p>代码</p>
<pre><code>if redis.call("get",KEYS[1]) == ARGV[1] then
return redis.call("del",KEYS[1])
else
return 0
end</code></pre></li>