From 21df7bc638597a358d6bd7dc6fe135406ba58023 Mon Sep 17 00:00:00 2001 From: Kadambini Panda <70250909+kadambinipanda@users.noreply.github.com> Date: Fri, 2 Oct 2020 14:43:22 +0530 Subject: [PATCH 1/2] Add files via upload --- 05_mixed_sorting.py | 72 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 05_mixed_sorting.py diff --git a/05_mixed_sorting.py b/05_mixed_sorting.py new file mode 100644 index 000000000..158f8b6b2 --- /dev/null +++ b/05_mixed_sorting.py @@ -0,0 +1,72 @@ +# Mixed sorting + +""" +Given a list of integers nums, sort the array such that: + +All even numbers are sorted in increasing order +All odd numbers are sorted in decreasing order +The relative positions of the even and odd numbers remain the same +Example 1 +Input + +nums = [8, 13, 11, 90, -5, 4] +Output + +[4, 13, 11, 8, -5, 90] +Explanation + +The even numbers are sorted in increasing order, the odd numbers are sorted in +decreasing number, and the relative positions were +[even, odd, odd, even, odd, even] and remain the same after sorting. +""" + +# solution + +import unittest + + +def mixed_sorting(nums): + positions = [] + odd = [] + even = [] + sorted_list = [] + for i in nums: + if i%2 == 0: + even.append(i) + positions.append("E") + else: + odd.append(i) + positions.append("O") + even.sort() + odd.sort() + odd.reverse() + j,k = 0,0 + for i in range(len(nums)): + if positions[i] == "E": + while j < len(even): + sorted_list.append(even[j]) + j += 1 + break + else: + while k < len(odd): + sorted_list.append(odd[k]) + k += 1 + break + + return sorted_list + + +# DO NOT TOUCH THE BELOW CODE + + +class TestMixedSorting(unittest.TestCase): + def test_1(self): + self.assertEqual(mixed_sorting( + [8, 13, 11, 90, -5, 4]), [4, 13, 11, 8, -5, 90]) + + def test_2(self): + self.assertEqual(mixed_sorting([1, 2, 3, 6, 5, 4]), [5, 2, 3, 4, 1, 6]) + + +if __name__ == '__main__': + unittest.main(verbosity=2) From 9d2a6b981b24852f7d251ee1f23d2c6e23a01f71 Mon Sep 17 00:00:00 2001 From: Kadambini Panda <221910305018@gitam.in> Date: Thu, 17 Dec 2020 17:14:45 +0530 Subject: [PATCH 2/2] Update and rename 05_mixed_sorting.py to two sum --- 05_mixed_sorting.py | 72 --------------------------------------------- two sum | 12 ++++++++ 2 files changed, 12 insertions(+), 72 deletions(-) delete mode 100644 05_mixed_sorting.py create mode 100644 two sum diff --git a/05_mixed_sorting.py b/05_mixed_sorting.py deleted file mode 100644 index 158f8b6b2..000000000 --- a/05_mixed_sorting.py +++ /dev/null @@ -1,72 +0,0 @@ -# Mixed sorting - -""" -Given a list of integers nums, sort the array such that: - -All even numbers are sorted in increasing order -All odd numbers are sorted in decreasing order -The relative positions of the even and odd numbers remain the same -Example 1 -Input - -nums = [8, 13, 11, 90, -5, 4] -Output - -[4, 13, 11, 8, -5, 90] -Explanation - -The even numbers are sorted in increasing order, the odd numbers are sorted in -decreasing number, and the relative positions were -[even, odd, odd, even, odd, even] and remain the same after sorting. -""" - -# solution - -import unittest - - -def mixed_sorting(nums): - positions = [] - odd = [] - even = [] - sorted_list = [] - for i in nums: - if i%2 == 0: - even.append(i) - positions.append("E") - else: - odd.append(i) - positions.append("O") - even.sort() - odd.sort() - odd.reverse() - j,k = 0,0 - for i in range(len(nums)): - if positions[i] == "E": - while j < len(even): - sorted_list.append(even[j]) - j += 1 - break - else: - while k < len(odd): - sorted_list.append(odd[k]) - k += 1 - break - - return sorted_list - - -# DO NOT TOUCH THE BELOW CODE - - -class TestMixedSorting(unittest.TestCase): - def test_1(self): - self.assertEqual(mixed_sorting( - [8, 13, 11, 90, -5, 4]), [4, 13, 11, 8, -5, 90]) - - def test_2(self): - self.assertEqual(mixed_sorting([1, 2, 3, 6, 5, 4]), [5, 2, 3, 4, 1, 6]) - - -if __name__ == '__main__': - unittest.main(verbosity=2) diff --git a/two sum b/two sum new file mode 100644 index 000000000..b4ba92ff3 --- /dev/null +++ b/two sum @@ -0,0 +1,12 @@ +class Solution(object): + def twoSum(self, nums, target): + """ + :type nums: List[int] + :type target: int + :rtype: List[int] + """ + l=len(nums) + for i in range(l): + for j in range(i,l): + if nums[i]+nums[j]==target: + return [i,j]