본문 바로가기

리트코드14

[코딩 테스트] 리트코드 2 - Add Two Numbers (Medium) in Python 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 두 정수 (> 0)가 연결리스트의 형태로 주어졌을 때, 두 정수를 더한 값을 연결리스트의 형태로 리턴하세요. 다만 연결리스트는 각 자리수가 역순.. 2021. 5. 22.
[코딩 테스트] 리트코드 1 - Two Sum (Easy) in Python Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. 2 List[int]: hashTable = {} for i in range(len(nums)): complement = target - nums[i] if complement in hashTable: return [i, hashTable[complement]] hashTable[nums[i]] = .. 2021. 5. 22.
[코딩 테스트] 리트코드 7 - Reverse Integer (Easy) in Python Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0. Assume the environment does not allow you to store 64-bit integers (signed or unsigned). Example 1: Input: x = 123 Output: 321 Example 2: Input x = -123 Output: -321 풀이 - 숫자를 문자로 변환해 - 거꾸로 만들되 - 음수라면 앞에 -를 넣어주고 - 다시 숫자로 .. 2021. 4. 30.
[코딩 테스트] 리트코드 6 - ZigZag Conversion (Medium) in Python 주어진 문자열을 numRows의 행에 따라 지그재그로 배열하여 결과문자열 리턴. The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) And then read line by line: "PAHNAPLSIIGYIR" Write the code that will take a string and make this conversion given a number of rows: string convert(string s, int numRows); Example .. 2021. 4. 30.