이카's
반응형
article thumbnail
자료구조 - 배열 (feat. Java, Python), 자매품 - Java Collection ArrayList
SW/자료구조 2023. 6. 1. 02:30

배열이란? 배열을 왜 쓸까? 같은 종류의 데이터를 관리하기 하기 위해서 같은 종류의 데이터를 순차적으로 저장 대전제는 데이터를 쉽게 관리하는 목적이다. 그것을 한 묶음으로 관리하는게 효율적이다. 근데 이걸 또 순차적으로 있다면? 한눈에 봐도 데이터를 다루기가 쉬울 것이다. 장점 - Index 배열의 가장 큰 장점은 Index라고 할 수 있다. 배열는 공간에 각각의 element 마다 각각의 index가 생긴다. (각각각각) 각 요소에 번호가 생기면 데이터 안에 하나의 값만 가져올 때 굉장히 편해진다. 또한 값을 찾을 때 소모되는 비용은 index로 인해 시간복잡도 O(1)을 가진다. 단점 - 배열의 크기설정 & 추가/삭제 배열의 가장 큰 단점 데이터를 삭제와 추가 하는 부분에서 발생한다. 배열은 크기를 ..

[Algorithm] LeetCode #6 Maximum Product Subarray

Problems Maximum Product Subarray Medium Given an integer array nums, find a contiguous non-empty subarray within the array that has the largest product, and return the product. The test cases are generated so that the answer will fit in a 32-bit integer. A subarray is a contiguous subsequence of the array. 인접한 원소들과 곱샘을 했을 때, 가장 큰 결과값을 반환 Example 1: Input: nums = [2,3,-2,4] Output: 6 Explanation..

[Algorithm] LeetCode #5 Maximum Subarray

Problems Maximum Subarray Easy Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. A subarray is a contiguous part of an array. Example 1: Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: [4,-1,2,1] has the largest sum = 6. Example 2: Input: nums = [1] Output: 1 Example 3: Input: nums = [5,4,-1,7,8] ..

[Algorithm] LeetCode #4 Product of Array Except Self

Problem 238 Product of Array Except Self Medium 12160 740 Add to List Share Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer. You must write an algorithm that runs in O(n) time and without using the division operation. Exa..

[Algorithm] LeetCode #3 Contains Duplicate

Problems Contains Duplicate Easy 4591 953 Add to List Share Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. Example 1: Input: nums = [1,2,3,1] Output: true Example 2: Input: nums = [1,2,3,4] Output: false Example 3: Input: nums = [1,1,1,3,3,4,3,2,4,2] Output: true 문제 이해 굉장히 쉬운 문제다. 배열안에 중복되는 숫자가 있으면 True없으면..

[Algorithm] LeetCode #2 Best time to buy and sell stock

LeetCode - Best time to buy and sell stock Problems 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 choosing a different day in the future to sell that stock. Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0. Example..

반응형