본문 바로가기

Facebook6

LeetCode.Single Number II Problem: Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. 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,3,2] Output: 3 Example 2: Input: [0,1,0,1,0,1,99] Output: 99 -Summary- Solved by using dictionary. 1. for each numbe.. 2020. 6. 23.
LeetCode 91. Decode Ways Problem: A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given a non-empty string containing only digits, determine the total number of ways to decode it. Example 1: Input: "12" Output: 2 Explanation: It could be decoded as "AB" (1 2) or "L" (12). Example 2: Input: "226" Output: 3 Explanation: It could be decoded as "B.. 2020. 6. 21.
LeetCode 41. First Missing Positive Problem: Given an unsorted integer array, find the smallest missing positive integer. Example 1: Input: [1,2,0] Output: 3 Example 2: Input: [3,4,-1,1] Output: 2 Example 3: Input: [7,8,9,11,12] Output: 1 -Summary- 1. Set first positive integer as 1 --> posNum 2. loop-through the nums and check if posNum is in the nums list. (max int: 2^31 -1) - if there is, adding 1 more value to posNum and find .. 2020. 6. 18.
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- Using XOR Bit operation 1. Do XOR bit operation for all numbers 2. return the answer EX.. 2020. 6. 17.
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 01. Two Sum Problem: Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the same element twice. Example: Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1]. Summary: 1. nums list를 돌며 target-num을 하였을때 다른 number가 dict 안에 있는지 확인. 2.. 2020. 5. 21.