본문 바로가기

전체 글60

[LeetCode] 53. Maximum Subarray 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] Output: 23 Constraints: 1 2022. 8. 15.
[Python] 2차원 배열 정렬 방법 Python의 list는 sort 함수를 기본적으로 제공한다. sort(key= 기준값, lambda 사용가능 , reverse= Boolean) 1. 기본 2차원 배열 정렬 list = [["kim", 80], ["kang", 90], ["jung", 50]] list.sort() print(list) sort 함수에 조건이 없다면 list[0]을 기준으로 오름차순 정렬된다. [['jung', 50], ['kang', 90], ['kim', 80]] 2. key에 labmda를 이용한 컬럼 정렬 sort에 key를 첫 번째 열(x[0])을 기준으로 세팅하게 된다면 위와 동일한 결과물을 얻을 수 있다. list.sort(key=lambda x:x[0]) 3. n번째 컬럼 기준 정렬 정렬 key를 변경함으.. 2022. 7. 31.
[Python] "return list.sort()"는 None 일 때 Python에서 List.sort()를 사용할 때 None이 return 된다. list = [1, 5, 4, 2, 3] print(list.sort()) 위의 코드은 None을 출력한다. 실제 sort()의 경우 return 값은 존재하지 않고 list 자체를 변경해 준다. 그러므로 list.sort()가 아닌 list를 출력한다면 변경 된 값을 확인할 수 있다. list = [1, 5, 4, 2, 3] list.sort() print(list) sort() 후 list를 출력하면 [1, 2, 3, 4, 5]가 출력된다. 2022. 7. 31.
[Spring][전문가를 위한 스프링 5] CH1. 스프링 소개 전문가를 위한 스프링 5(Pro Spring 5) - Ch 1. 스프링 소개 1.1 스프링이란? Spring은 Java Application 개발을 위한 경량 Framework이다. Apache Struts와 같은 단순 Web App 개발뿐만 아니라 다양한 형태의 Java Application 개발이 가능하다. 기존 App 코드에 최소한의 영향을 준다.(경량) 1.1.1 스프링 프레임워크의 발전 과정 Spring 0.9 버전 Bean, AOP, JDBC, 추상 Transaction 지원 Spring 1.X 버전 Spring Core, Context, Dao, ORM, AOP, WEB, WEB MVC Spring 2.X 버전 DTD 아닌 XML 스키마 구성지원 @Transactional, @AspectJ .. 2022. 7. 23.
[LeetCode] 38. Count and Say The count-and-say sequence is a sequence of digit strings defined by the recursive formula: countAndSay(1) = "1" countAndSay(n) is the way you would "say" the digit string from countAndSay(n-1), which is then converted into a different digit string. To determine how you "say" a digit string, split it into the minimal number of substrings such that each substring contains exactly one unique digit.. 2022. 7. 22.
[LeetCode] 35. Search Insert Position Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must write an algorithm with O(log n) runtime complexity. Example 1: Input: nums = [1,3,5,6], target = 5 Output: 2 Example 2: Input: nums = [1,3,5,6], target = 2 Output: 1 Example 3: Input: nums = [1,3,5,6], target = 7.. 2022. 7. 22.
[LeetCode] 28. Implement strStr() Implement strStr(). Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Clarification: What should we return when needle is an empty string? This is a great question to ask during an interview. For the purpose of this problem, we will return 0 when needle is an empty string. This is consistent to C's strs.. 2022. 7. 22.
[Leetcode] 27. Remove Element 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. Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the first part of the array nums. More formally, if there are k elements after removing the duplicates, then the first k elements.. 2022. 7. 22.
[LeetCode] 26. Remove Duplicates from Sorted Array Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the first part of the array nums. More formally, if there are k elements aft.. 2022. 7. 22.
반응형