Algorithm/Leet Code
-
[LeetCode/Python] 2. Add Two NumbersAlgorithm/Leet Code 2020. 7. 15. 17:20
2. Add Two Numbers Medium 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 contain a single digit. Add the two numbers and return it as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. # Definition for singly-linked list. class ListNode: def __i..
-
[LeetCode/Python] 700. Search in a Binary Search TreeAlgorithm/Leet Code 2020. 7. 15. 01:30
Description Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST that the node's value equals the given value. Return the subtree rooted with that node. If such node doesn't exist, you should return NULL. For example, Given the tree: 4 / \ 2 7 / \ 1 3 And the value to search: 2 You should return this subtree: 2 / \ 1 3 In the example above, if we wa..
-
[LeetCode/Python] 859. Buddy StringsAlgorithm/Leet Code 2020. 7. 12. 01:14
859. Buddy Strings Easy Given two strings A and B of lowercase letters, return true if and only if we can swap two letters in A so that the result equals B. class Solution: def buddyStrings(self, A: str, B: str) -> bool: if len(A) != len(B) : return False elif A == B : setA = list(set(list(A))) if len(setA) < len(A) : return True else : return False diff = [] for i in range(len(A)) : if A[i] != ..
-
[LeetCode/Python] 1221. Split a String in Balanced StringsAlgorithm/Leet Code 2020. 7. 12. 00:47
1221. Split a String in Balanced Strings Easy Balanced strings are those who have equal quantity of 'L' and 'R' characters. Given a balanced string s split it in the maximum amount of balanced strings. Return the maximum amount of splitted balanced strings. class Solution: def balancedStringSplit(self, s: str) -> int: length = len(s) result = 0 p = 0 for i in range(length) : if s[p:i+1].count('L..