본문 바로가기

LeetCode/Top Interview Q. - Easy47

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.
LeetCode 189. Rotate Array Problem: Given an array, rotate the array to the right by k steps, where k is non-negative. Follow up: Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem. Could you do it in-place with O(1) extra space? Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 step.. 2020. 5. 22.
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.
LeetCode 36. Valid Sudoku [Medium] 문제: Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: Each row must contain the digits 1-9 without repetition. Each column must contain the digits 1-9 without repetition. Each of the 9 3x3 sub-boxes of the grid must contain the digits 1-9 without repetition. A partially filled sudoku which is valid. The Sudoku board could be pa.. 2020. 5. 20.
LeetCode 344. Reverse String [Easy] 문제: Write a function that reverses a string. The input string is given as an array of characters char[]. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. You may assume all the characters consist of printable ascii characters. Example 1: Input: ["h","e","l","l","o"] Output: ["o","l","l","e","h"] Example 2: Input: ["H",".. 2020. 5. 20.