python

Coding Test

[TIL/05.08] Leetcode: Best Time to Buy and Sell Stock (Python)

문제https://leetcode.com/problems/best-time-to-buy-and-sell-stock/ You 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, retur..

Coding Test

[TIL/05.07] Leetcode: 3Sum (Python)

문제Link Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.Notice that the solution set must not contain duplicate triplets. Example 1:Input: nums = [-1,0,1,2,-1,-4]Output: [[-1,-1,2],[-1,0,1]]Explanation: nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0.nums[1] + nums[2] + nums[4] = 0 + 1 + (-1..

Coding Test

[TIL/05.07] Leetcode: Group Anagrams (Python)

문제A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.Given a string s, return true if it is a palindrome, or false otherwise. Example 1:Input: s = "A man, a plan, a canal: Panama"Output: trueExplanation: "amanaplanacanal..

Coding Test

[TIL/05.06] Leetcode: Group Anagrams (Python)

문제Given an array of strings strs, group the anagrams together. You can return the answer in any order.문자열을 받아 애너그램 단위로 그루핑하라.  입출력 예시Example 1:Input: strs = ["eat","tea","tan","ate","nat","bat"]Output: [["bat"],["nat","tan"],["ate","eat","tea"]]Example 2:Input: strs = [""]Output: [[""]]Example 3:Input: strs = ["a"]Output: [["a"]] 해설 풀이from collections import defaultdictclass Solution: def gro..

Yeni.Yeni
'python' 태그의 글 목록