🔥✅✅ Beat 97.22% | ✅ Full explanation with pictures ✅✅🔥
Show your appreciation by clicking the upvote button\n\n\n\n\n\n\n\n\npython []\nclass Solution(object):\n    def insert(self, intervals, newInterval):\n       
Show your appreciation by clicking the upvote button\n![Screen Shot 2024-03-14 at 11.30.19.png](https://assets.leetcode.com/users/images/99fe0b15-b318-4601-af0f-574bc98640ee_1710652249.4421208.png)\n\n[![Screen Shot 2024-03-17 at 05.44.09.png](https://assets.leetcode.com/users/images/d0612ffc-8124-450d-95e0-e873dc91c7be_1710636273.726533.png)](https://leetcode.com/problems/insert-interval/submissions/1205776282)\n\n![AtomicHubUi 2.png](https://assets.leetcode.com/users/images/b4030676-5521-4112-829c-6f5e43bd4a80_1710633960.279035.png)\n\n![Screen Shot 2024-03-14 at 11.30.19.png](https://assets.leetcode.com/users/images/1a000871-2ca5-4e16-9fcf-5ce452bbfc5d_1710636998.6955018.png)\n\n```python []\nclass Solution(object):\n    def insert(self, intervals, newInterval):\n        merged = []\n        i = 0\n\n        while i < len(intervals) and intervals[i][1] < newInterval[0]:\n            merged.append(intervals[i])\n            i += 1\n        \n        while i < len(intervals) and intervals[i][0] <= newInterval[1]:\n            newInterval = [min(newInterval[0], intervals[i][0]), max(newInterval[1], intervals[i][1])]\n            i += 1\n        merged.append(newInterval)\n        \n        while i < len(intervals):\n            merged.append(intervals[i])\n            i += 1\n        \n        return merged\n```\n```python3 []\nclass Solution:\n    def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:\n        merged = []\n        i = 0\n\n        while i < len(intervals) and intervals[i][1] < newInterval[0]:\n            merged.append(intervals[i])\n            i += 1\n        \n        while i < len(intervals) and intervals[i][0] <= newInterval[1]:\n            newInterval = [min(newInterval[0], intervals[i][0]), max(newInterval[1], intervals[i][1])]\n            i += 1\n        merged.append(newInterval)\n        \n        while i < len(intervals):\n            merged.append(intervals[i])\n            i += 1\n        \n        return merged\n```\n```C++ []\nclass Solution {\npublic:\n    vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) {\n        vector<vector<int>> merged;\n        int i = 0;\n\n        while (i < intervals.size() && intervals[i][1] < newInterval[0]) {\n            merged.push_back(intervals[i]);\n            i++;\n        }\n\n        while (i < intervals.size() && intervals[i][0] <= newInterval[1]) {\n            newInterval = {min(newInterval[0], intervals[i][0]), max(newInterval[1], intervals[i][1])};\n            i++;\n        }\n        merged.push_back(newInterval);\n\n        while (i < intervals.size()) {\n            merged.push_back(intervals[i]);\n            i++;\n        }\n\n        return merged;\n    }\n};\n```\n```javascript []\nvar insert = function(intervals, newInterval) {\n    let merged = [];\n    let i = 0;\n\n    while (i < intervals.length && intervals[i][1] < newInterval[0]) {\n        merged.push(intervals[i]);\n        i++;\n    }\n\n    while (i < intervals.length && intervals[i][0] <= newInterval[1]) {\n        newInterval = [Math.min(newInterval[0], intervals[i][0]), Math.max(newInterval[1], intervals[i][1])];\n        i++;\n    }\n    merged.push(newInterval);\n\n    while (i < intervals.length) {\n        merged.push(intervals[i]);\n        i++;\n    }\n\n    return merged;\n};\n```\n![Screen Shot 2024-03-14 at 11.30.19.png](https://assets.leetcode.com/users/images/99fe0b15-b318-4601-af0f-574bc98640ee_1710652249.4421208.png)\n\n## **My solutions**\n\n\uD83D\uDFE2 - $$easy$$  \n\uD83D\uDFE1 - $$medium$$ \n\uD83D\uDD34 - $$hard$$\n\n\n\n\uD83D\uDFE1 [104. Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/solutions/4876170/beat-100-full-explanation-with-pictures)\n\n\uD83D\uDFE1 [46. Permutations](https://leetcode.com/problems/permutations/solutions/4853218/beat-98-64-full-explanation-with-pictures)\n\uD83D\uDFE1 [17. Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/solutions/4845532/there-is-an-80-chance-of-being-in-the-interview-full-problem-explanation)\n\uD83D\uDFE1 [22. Generate Parentheses](https://leetcode.com/problems/generate-parentheses/solutions/4845742/simple-explanation-with-pictures)\n\uD83D\uDFE1 [39. Combination Sum](https://leetcode.com/problems/combination-sum/solutions/4847482/beat-8292-full-explanation-with-pictures)\n\uD83D\uDFE2 [2540. Minimum Common Value](https://leetcode.com/problems/minimum-common-value/solutions/4845076/beat-9759-full-explanation-with-pictures)\n\uD83D\uDFE2 [3005. Count Elements With Maximum Frequency](https://leetcode.com/problems/count-elements-with-maximum-frequency/solutions/4839796/beat-8369-full-explanation-with-pictures)\n\uD83D\uDFE2 [3028. Ant on the Boundary](https://leetcode.com/problems/ant-on-the-boundary/solutions/4837433/full-explanation-with-pictures)\n\uD83D\uDFE2 [876. Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list/solutions/4834682/beat-10000-full-explanation-with-pictures)\n\uD83D\uDFE1 [1750. Minimum Length of String After Deleting Similar Ends](https://leetcode.com/problems/minimum-length-of-string-after-deleting-similar-ends/solutions/4824224/beat-10000-full-explanation-with-pictures)\n\uD83D\uDFE1 [948. Bag of Tokens](https://leetcode.com/problems/bag-of-tokens/solutions/4818912/beat-10000-full-explanation-with-pictures)\n\uD83D\uDFE1 [19. Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/solutions/4813340/beat-10000-full-explanation-with-pictures)\n\uD83D\uDFE2 [977. Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array/solutions/4807704/square-sorter-python-python3-javascript-c)\n\uD83D\uDFE2 [2864. Maximum Odd Binary Number](https://leetcode.com/problems/maximum-odd-binary-number/solutions/4802402/visual-max-odd-binary-solver-python-python3-javascript-c)\n\uD83D\uDFE1 [1609. Even Odd Tree](https://leetcode.com/problems/even-odd-tree/solutions/4797529/even-odd-tree-validator-python-python3-javascript-c)\n\uD83D\uDFE2 [9. Palindrome Number](https://leetcode.com/problems/palindrome-number/solutions/4795373/why-not-1-line-of-code-python-python3-c-everyone-can-understand)\n\uD83D\uDFE1 [513. Find Bottom Left Tree Value](https://leetcode.com/problems/find-bottom-left-tree-value/solutions/4792022/binary-tree-explorer-mastered-javascript-python-python3-c-10000-efficiency-seeker)\n\uD83D\uDFE2 [1. Two Sum](https://leetcode.com/problems/two-sum/solutions/4791305/5-methods-python-c-python3-from-easy-to-difficult)\n\uD83D\uDFE2 [543. Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree/solutions/4787634/surpassing-9793-memory-magician-excelling-at-9723)\n\uD83D\uDFE2 [101. Symmetric Tree](https://leetcode.com/problems/symmetric-tree/solutions/4848126/beat-100-full-explanation-with-pictures)\n\uD83D\uDFE2 [136. Single Number](https://leetcode.com/problems/single-number/solutions/4862807/master-the-xor-trick-beat-97-20-with-full-explanation)\n\uD83D\uDFE2 [283. Move Zeroes](https://leetcode.com/problems/move-zeroes/solutions/4864068/mastering-efficiency-beat-98-71)\n\uD83D\uDFE2 [108. Convert Sorted Array to Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/solutions/4864578/beat-89-74-full-explanation-with-pictures)\n\n[More...](https://leetcode.com/DevOgabek/)\n
['Array', 'Python', 'C++', 'Python3', 'JavaScript']