https://i.imgur.com/T0fcnXo.png

[LeetCode] 88. Merge Sorted Array

Merge Sorted Array Link to original Problem on LeetCode Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: The number of elements initialized in nums1 and nums2 are m and n respectively. You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. Example: Input: nums1 = [1,2,3,0,0,0], m = 3 nums2 = [2,5,6], n = 3

[LeetCode] 905. Sort Array By Parity

Sort Array By Parity Link to original Problem on LeetCode Given an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A. You may return any answer array that satisfies this condition. Example 1: Input: [3,1,2,4] Output: [2,4,3,1] The outputs [4,2,3,1], [2,4,1,3], and [4,2,1,3] would also be accepted. Note: 1 <= A.length <= 5000 0 <= A[i] <= 5000

[LeetCode] 144. Binary Tree Preorder Traversal

Binary Tree Preorder Traversal Link to original Problem on LeetCode Given a binary tree, return the preorder traversal of its nodes’ values. Example: Output: [1, 3, 2] Follow up: Recursive solution is trivial, could you do it iteratively? Company: Microsoft, Amazon Recursive Solution: # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution(object): def preorderTraversal(self, root): """ :type root: TreeNode :rtype: List[int] """ # Runtime: 16 ms # Memory Usage: 11.

[LeetCode] 145. Binary Tree Postorder Traversal

Binary Tree Postorder Traversal Link to original Problem on LeetCode Given a binary tree, return the postorder traversal of its nodes’ values. Example: Output: [3,2,1] Follow up: Recursive solution is trivial, could you do it iteratively? Company: Microsoft, Amazon Recursive Solution: # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution(object): def postorderTraversal(self, root): """ :type root: TreeNode :rtype: List[int] """ # Runtime: 16 ms # Memory Usage: 11.

[LeetCode] 94. Binary Tree Inorder Traversal

Binary Tree Inorder Traversal Link to original Problem on LeetCode Given a binary tree, return the inorder traversal of its nodes’ values. Example: Output: [1, 2, 3] Follow up: Recursive solution is trivial, could you do it iteratively? Company: Microsoft, Amazon Recursive Solution: # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution(object): def inorderTraversal(self, root): """ :type root: TreeNode :rtype: List[int] """ # Runtime: 12 ms # Memory Usage: 11.

[LeetCode] 1. Two Sum

Two Sum Link to original Problem on LeetCode Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the same element twice. Example: Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1].