본문 바로가기

컴퓨터공학 & 정보통신88

[LeetCode] 2. Add Two Numbers 접근 두 노드를 순회하며 계산 친절하게도 이미 거꾸로 뒤업어 놓았음 carry 를 활용해서 모든 경우의 수에 부합하는 보편적인 문제 해결 방식을 찾아야 솔루션 class Solution: def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]: answer = ListNode(0, None) answer_cursor = answer carry = 0 while l1 != None or l2 != None or carry != 0: l1Value = 0 l2Value = 0 if l1: l1Value = l1.val if l2: l2Value = l2.val sumOfValue = l1Value.. 2023. 3. 13.
[GeeksforGeeks] Special array reversal Special array reversal | Practice | GeeksforGeeks Given a string S, containing special characters and all the alphabets, reverse the string without affecting the positions of the special characters. Example 1: Input: S = "A&B" Output: "B&A" Explanation: As we i practice.geeksforgeeks.org 접근 Two pointer 를 활용해 문자 비교 및 변경 isalphabet() 함수를 활용 Python 문자열 내 두 문자를 스왑하는 함수가 따로 제공되지 않는다는 점 참고 솔루션 class S.. 2023. 2. 22.
[LeetCode] 1971. Find if Path Exists in Graph https://leetcode.com/problems/find-if-path-exists-in-graph Find if Path Exists in Graph - LeetCode Can you solve this real interview question? Find if Path Exists in Graph - There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1 (inclusive). The edges in the graph are represented as a 2D integer array edges, where leetcode.com 접근 BFS 또는 DFS 로 탐색하는 문제 graph,.. 2023. 2. 15.
[LeetCode] 989. Add to Array-Form of Integer https://leetcode.com/problems/add-to-array-form-of-integer Add to Array-Form of Integer - LeetCode Add to Array-Form of Integer - The array-form of an integer num is an array representing its digits in left to right order. * For example, for num = 1321, the array form is [1,3,2,1]. Given num, the array-form of an integer, and an integer k, return the ar leetcode.com 접근 정수 배열인 num 을 정수로 바꾸어 num 과.. 2023. 2. 15.
[LeetCode] 278. First Bad Version https://leetcode.com/problems/first-bad-version/ 피봇을 사용하여 탐색하는 문제입니다. First Bad Version - LeetCode Can you solve this real interview question? First Bad Version - You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed base leetcode.com 솔루션 # The isBadVersion API is.. 2023. 2. 13.
[LeetCode] 205. Isomorphic Strings 제 3의 문자열로 표현하여 문제를 해결할 수 있습니다. https://leetcode.com/problems/isomorphic-strings/ Isomorphic Strings - LeetCode Isomorphic Strings - Given two strings s and t, determine if they are isomorphic. Two strings s and t are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another character while preserving th leetcode.com 솔루션 class Solutio.. 2023. 2. 13.