Skip to content

Commit 144de8a

Browse files
committed
Create README - LeetHub
1 parent d475e72 commit 144de8a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

0147-insertion-sort-list/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<h2><a href="https://leetcode.com/problems/insertion-sort-list/">147. Insertion Sort List</a></h2><h3>Medium</h3><hr><div><p>Given the <code>head</code> of a singly linked list, sort the list using <strong>insertion sort</strong>, and return <em>the sorted list's head</em>.</p>
2+
3+
<p>The steps of the <strong>insertion sort</strong> algorithm:</p>
4+
5+
<ol>
6+
<li>Insertion sort iterates, consuming one input element each repetition and growing a sorted output list.</li>
7+
<li>At each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list and inserts it there.</li>
8+
<li>It repeats until no input elements remain.</li>
9+
</ol>
10+
11+
<p>The following is a graphical example of the insertion sort algorithm. The partially sorted list (black) initially contains only the first element in the list. One element (red) is removed from the input data and inserted in-place into the sorted list with each iteration.</p>
12+
<img alt="" src="https://upload.wikimedia.org/wikipedia/commons/0/0f/Insertion-sort-example-300px.gif" style="height:180px; width:300px">
13+
<p>&nbsp;</p>
14+
<p><strong class="example">Example 1:</strong></p>
15+
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/04/sort1linked-list.jpg" style="width: 422px; height: 222px;">
16+
<pre><strong>Input:</strong> head = [4,2,1,3]
17+
<strong>Output:</strong> [1,2,3,4]
18+
</pre>
19+
20+
<p><strong class="example">Example 2:</strong></p>
21+
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/04/sort2linked-list.jpg" style="width: 542px; height: 222px;">
22+
<pre><strong>Input:</strong> head = [-1,5,3,4,0]
23+
<strong>Output:</strong> [-1,0,3,4,5]
24+
</pre>
25+
26+
<p>&nbsp;</p>
27+
<p><strong>Constraints:</strong></p>
28+
29+
<ul>
30+
<li>The number of nodes in the list is in the range <code>[1, 5000]</code>.</li>
31+
<li><code>-5000 &lt;= Node.val &lt;= 5000</code></li>
32+
</ul>
33+
</div>

0 commit comments

Comments
 (0)