본문 바로가기

leet code41

[LEET CODE] 24. Swap Nodes in Pairs # Problem Given a linked list, swap every two adjacent nodes and return its head. Constraints: The number of nodes in the list is in the range [0, 100]. 0 ListNode: cur = head while cur and cur.next: # 값만 교환 cur.val, cur.next.val = cur.next.val, cur.val cur = cur.next.next return head # Solution 2 - 반복 구조로 스왑 # Definition for singly-linked list. class ListNode: def __init__(self, x): self.val = .. 2021. 3. 23.
[LEET CODE] 2. Add Two Numbers ( 숫자형 리스트 병합하기) # Problem You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. Constraints: The number of nodes in each linked list is in the range .. 2021. 3. 22.
[LEET CODE] 49. Group Anagrams (dict 자료형, sort(), sorted()) # Problem * anagram(애너그램) : 일종의 언어유희로 문자를 재배열하여 다른 뜻을 가진 단어로 바꾸는 것 Given an array of strings strs, group the anagrams together. You can return the answer in any order. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. Example 1: Input : strs = ["eat","tea","tan","ate","nat","bat"] Output : [["bat.. 2021. 3. 15.
[LEET CODE] 819. Most Common Word ( 정규표현식 ) #Problem Given a string paragraph and a string array of the banned words banned, return the most frequent word that is not banned. It is guaranteed there is at least one word that is not banned, and that the answer is unique. The words in paragraph are case-insensitive and the answer should be returned in lowercase. Example 1: Input : paragraph : "Bob hit a ball, the hit BALL flew far after it w.. 2021. 3. 15.
[LEET CODE] 937. Reorder Data in Log Files ( lambda 함수, 문자열 확인 함수 ) # Problem You are given an array of logs. Each log is a space-delimited string of words, where the first word is the identifier. There are two types of logs: Letter-logs: All words (except the identifier) consist of lowercase English letters. Digit-logs: All words (except the identifier) consist of digits. Reorder these logs so that: The letter-logs come before all digit-logs. The letter-logs ar.. 2021. 3. 14.
반응형