[LeetCode] 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. 주어진 배열의 부분 배열(subarray)의 합 중 최대값을 구하시오. 부분 매열은 연속적인(contiguous) 배열이어야 한다. [1,2,3,4] 배열을 예시로 들자면, [1,2]는 부분배열로 가능하지만, [1,3]또는 [1,4]와 같이 연속적이지 않고 서로 떨어져 있는 값들은 조건에 어긋난다. 예시 Example 1: Input: nums = [-2,1,-3,4,-1,2,1..
[LeetCode] Remove Element | 난이도: Easy
문제 Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The relative order of the elements may be changed. 정수 배열 nums, 정수 타입의 변수 val가 있다. 배열 nums의 값 중에서 변수 val의 값과 일치하는 값을 뺀 배열의 길이를 구하시오. 예시 Input: nums = [3,2,2,3], val = 3 Output: 2, nums = [2,2,_,_] 답안 class Solution { public int removeElement(int[] nums, int val) { int result = 0; for(int i = 0; i i+..
[LeetCode] Merge Two Sorted List | 난이도: Easy
문제 Merge two sorted linked lists and return it as a sorted list. The list should be made by splicing together the nodes of the first two lists. 주어진 두 연결 리스트(Linked List)를 합쳐서 정렬된 하나의 리스트로 만들어라. 예시 Input: l1 = [1,2,4], l2 = [1,3,4] Output: [1,1,2,3,4,4] Input: l1 = [], l2 = [0] Output: [0] Input: l1 = [], l2 = [] Output: [] 답안 /** * Definition for singly-linked list. * public class ListNode { * i..