본문 바로가기

전체 글

(49)
[Java Script]LeetCode 121. Best Time to Buy and Sell Stock 1. 문제 개요 문제 링크 : 121. Best Time to Buy and Sell Stock Best Time to Buy and Sell Stock - LeetCode Can you solve this real interview question? Best Time to Buy and Sell Stock - You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day to buy one stock and choosin leetcode.com 주어진 배열은 주식을 거래하고 팔 수 있는 날자별 수익이..
[Java Script]LeetCode 189. Rotate Array 1. 문제 개요 문제 링크 : 189. Rotate Array Rotate Array - LeetCode Can you solve this real interview question? Rotate Array - Given an integer array nums, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 step leetcode.com 주어진 배열을 함께 주어진 변수의 수만큼 회전하여라 2. 문제 풀이 단순하게 회전을 구현하는 문제여서 쉽게 접근하였지만 테스트 시..
[Java Script]LeetCode 169. Majority Element 1. 문제 개요 문제 링크 : 169. Majority Element 주어지는 배열에서 중복값이 가장 많은 원자값을 찾아내시오 2. 문제 풀이 배열의 원자값중 중복값이 가장많은 값을 고르는 방식이기에 80번 문제에서 사용한것과 동일한 방식을 이용하여 선 정렬후 배열 탐색 과정에서 전후값을 비교하여 개수를 체크하는 방식으로 풀어보겠습니다 이를 구현하기 위해 주석으로 코드의 구조를 잡아보면 다음과 같은데 var majorityElement = function(nums) { // 탐색할 필요하 겂는경우 체크(배열의 길이가 1) // 주어진 배열값 정렬 // 전후값을 비교하여 중복값을 카운팅 하는 반복문 구현 // 최대 중복값 카운트 값 반환 }; LeetCode 요구 양식으로 코드 구현 var majority..