본문 바로가기

Python130

LeetCode 350. Intersection of Two Arrays II Problem: Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1], nums2 = [2,2] Output: [2,2] Example 2: Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4] Output: [4,9] -Summary- Using the dictionary 1. Create a dictionary to hold an all numbers as a 'key' in the first nums1 list (Count +1 for each key) 2. Loop the second nums2 list and only append to answ.. 2020. 5. 24.
LeetCode 136. Single Number Problem Given a non-empty array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Example 1: Input: [2,2,1] Output: 1 Example 2: Input: [4,1,2,1,2] Output: 4 -Summary- #By using bit manipulation (no extra memory) 1. for each num in the nums list, do XOR bi.. 2020. 5. 23.
LeetCode 217. Contains Duplicate Problem Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct. Example 1: Input: [1,2,3,1] Output: true Example 2: Input: [1,2,3,4] Output: false Example 3: Input: [1,1,1,3,3,4,3,2,4,2] Output: true -Summary- 1. Compare the length of the orig.. 2020. 5. 23.
LeetCode 122. Best Time to Buy and Sell Stock II Problem Say you have an array prices for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times). Note: You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again). Example 1: I.. 2020. 5. 23.
CodeSignal [33/60] stringsRearrangement Problem Given an array of equal-length strings, you'd like to know if it's possible to rearrange the order of the elements in such a way that each consecutive pair of strings differ by exactly one character. Return true if it's possible, and false if not. Note: You're only rearranging the order of the strings, not the order of the letters within the strings! Example For inputArray = ["aba", "bbb.. 2020. 5. 23.
LeetCode 283. Move Zeroes Problem: Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. Example: Input: [0,1,0,3,12] Output: [1,3,12,0,0] -Summary- Used two-pointer using two loops. 1. set 1 pointer of for loop for the zero-value index in the nums list. 2. If zero index found, then we loop starting from the next index then find the number th.. 2020. 5. 22.