This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def sum_of_nums(nums): | |
| if len(nums) == 1: | |
| return nums[0] | |
| first_num = nums[0] | |
| rest = nums[1:] | |
| return first_num + sum_of_nums(rest) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def cyclic_sort(nums): | |
| start = 0 | |
| while start < len(nums): | |
| swap = nums[start] - 1 | |
| if nums[start] != nums[swap]: | |
| nums[start], nums[swap] = nums[swap], nums[start] | |
| else: | |
| start += 1 |