diff --git a/Leetcode-Easy/1920. Build Array With Permutations/Build Array With Permutations.cpp b/Leetcode-Easy/1920. Build Array With Permutations/Build Array With Permutations.cpp new file mode 100644 index 0000000..7d961c6 --- /dev/null +++ b/Leetcode-Easy/1920. Build Array With Permutations/Build Array With Permutations.cpp @@ -0,0 +1,17 @@ +/* + * @lc app=leetcode id=1920 lang=cpp + * + * [1920] Build Array from Permutation + */ + +class Solution +{ +public: + vector buildArray(vector &nums) + { + vector rez; + for (int i = 0; i < nums.size(); i++) + rez.push_back(nums[nums[i]]); + return rez; + } +}; \ No newline at end of file diff --git a/Leetcode-Easy/21-MergeTwoSortedList/21.Merge Two Sorted Array.cpp b/Leetcode-Easy/21-MergeTwoSortedList/21.Merge Two Sorted Array.cpp new file mode 100644 index 0000000..8cfbba6 --- /dev/null +++ b/Leetcode-Easy/21-MergeTwoSortedList/21.Merge Two Sorted Array.cpp @@ -0,0 +1,73 @@ +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * ListNode *next; + * ListNode() : val(0), next(nullptr) {} + * ListNode(int x) : val(x), next(nullptr) {} + * ListNode(int x, ListNode *next) : val(x), next(next) {} + * }; + */ +class Solution +{ +public: + ListNode *mergeTwoLists(ListNode *list1, ListNode *list2) + { + if (list1 == NULL && list2 == NULL) + { + return list1; + } + else if (list1 == NULL && list2 != NULL) + { + return list2; + } + else if (list1 != NULL && list2 == NULL) + { + return list1; + } + + ListNode *list3, *last; + + if (list1->val < list2->val) + { + list3 = last = list1; + list1 = list1->next; + last->next = NULL; + } + else + { + list3 = last = list2; + list2 = list2->next; + last->next = NULL; + } + + while (list1 && list2) + { + if (list1->val < list2->val) + { + last->next = list1; + list1 = list1->next; + last = last->next; + last->next = NULL; + } + else + { + last->next = list2; + list2 = list2->next; + last = last->next; + last->next = NULL; + } + } + + if (list1 != NULL && list2 == NULL) + { + last->next = list1; + } + else + { + last->next = list2; + } + + return list3; + } +}; \ No newline at end of file