Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Create: 0147-insertion-sort-list.java#3231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
MHamiid merged 1 commit intoneetcode-gh:mainfroma1exanddrovich:0147-dev
Jan 14, 2024
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Create: 0147-insertion-sort.java
Signed-off-by: Aliaksei <a1exandddrovich@gmail.com>
  • Loading branch information
@a1exanddrovich
a1exanddrovich committedJan 13, 2024
commitbc385d0e63e54ed36eade81c7f7b810efb9d7551
27 changes: 27 additions & 0 deletionsjava/0147-insertion-sort-list.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
class Solution {
public ListNode insertionSortList(ListNode head) {
ListNode dummy = new ListNode(0, head);

ListNode prev = head;
ListNode cur = head.next;
while (cur != null) {
if (prev.val <= cur.val) {
prev = cur;
cur = cur.next;
} else {
ListNode elem = dummy;
while (elem.next.val < cur.val) {
elem = elem.next;
}

prev.next = cur.next;
cur.next = elem.next;
elem.next = cur;

cur = prev.next;
}
}

return dummy.next;
}
}

[8]ページ先頭

©2009-2025 Movatter.jp