Grind75 - 226. Invert Binary Tree 파이썬
·
알고리즘/LeetCode_Grind75
226. Invert Binary TreeEasyGiven the root of a binary tree, invert the tree, and return its root. Example 1:Input: root = [4,2,7,1,3,6,9]Output: [4,7,2,9,6,3,1]Example 2:Input: root = [2,1,3]Output: [2,3,1]Example 3:Input: root = []Output: [] Constraints:The number of nodes in the tree is in the range [0, 100].-100  나의 코드class TreeNode: def __init__(self, val=0, left=None, right=None): ..
Grind75 - 21. Merge Two Sorted Lists 파이썬
·
알고리즘/LeetCode_Grind75
21. Merge Two Sorted ListsEasyYou are given the heads of two sorted linked lists list1 and list2.Merge the two lists into one sorted list. The list should be made by splicing together the nodes of the first two lists.Return the head of the merged linked list. Example 1:Input: list1 = [1,2,4], list2 = [1,3,4]Output: [1,1,2,3,4,4]Example 2:Input: list1 = [], list2 = []Output: []Example 3:Input: li..
Grind75 - 121. Best Time to Buy and Sell Stock 파이썬
·
알고리즘/LeetCode_Grind75
121. Best Time to Buy and Sell StockEasyYou are given an array prices where prices[i] is the price of a given stock on the ith day.You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0. Example 1:Input: pric..
Grind75 - 704. Binary Search 파이썬
·
알고리즘/LeetCode_Grind75
704. Binary SearchEasyGiven an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.You must write an algorithm with O(log n) runtime complexity. Example 1:Input: nums = [-1,0,3,5,9,12], target = 9Output: 4Explanation: 9 exists in nums and its index is 4Example 2:..
컴공편입생 공부일기
'알고리즘/LeetCode_Grind75' 카테고리의 글 목록