leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 8c3de239888904aa4a7ccb16ff368b48c765ee5f
parent b6795bb18ebf9505a5e6e639b4e49e14aa5207c5
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Fri, 14 Apr 2023 12:28:47 -0500

Sort singly linked list

Diffstat:
Arising-temperature/rising-temp.sql | 8++++++++
Asort-list/a.out | 0
Asort-list/sort-list.cpp | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/rising-temperature/rising-temp.sql b/rising-temperature/rising-temp.sql @@ -0,0 +1,8 @@ +--Runtime 589ms Beats 97.92% + + +SELECT W.id Id +FROM Weather W +LEFT JOIN Weather W1 +ON SUBDATE(W1.recordDate, -1) = W.recordDate +WHERE W1.temperature < W.temperature diff --git a/sort-list/a.out b/sort-list/a.out Binary files differ. diff --git a/sort-list/sort-list.cpp b/sort-list/sort-list.cpp @@ -0,0 +1,54 @@ +#include <iostream> +#include <vector> +#include <algorithm> +using namespace std; + +//Runtime: 172ms Beats: 98.86% +//Memory: 53.2MB Beats: 71% + + +struct ListNode{ + int val; + ListNode* next; + + +}; + + + +ListNode* sortList(ListNode* head) { + vector<int> sorted; + ListNode* itr = head; + ListNode* itr1 = head; + while(itr!= NULL){ + sorted.push_back(itr->val); + itr=itr->next; + } + sort(sorted.begin(), sorted.end()); + for(int i = 0; i < sorted.size(); ++i){ + itr1->val = sorted[i]; + itr1 = itr1->next; + } + + return head; +} + +int main(){ + ListNode* l1 = new ListNode; + ListNode* ln2 = new ListNode; + ListNode* ln3 = new ListNode; + ListNode* ln4 = new ListNode; + l1->val = 0; + ln2->val = 10; + ln3->val = 4; + ln4->val = -1; + l1->next = ln2; + ln2->next = ln3; + ln3->next = ln4; + ListNode* l2 = sortList(l1); + while(l2 != NULL){ + cout << l2->val << " " ; + l2 = l2->next; + } + cout << endl; +}