[파이썬/알고리즘] Leetcode - 937. Reorder Data in Log Files
알고리즘/LeetCode 2021. 7. 3. 14:45

[문제] You are given an array of logs. Each log is a space-delimited string of words, where the first word is the identifier. There are two types of logs: Letter-logs: All words (except the identifier) consist of lowercase English letters. Digit-logs: All words (except the identifier) consist of digits. Reorder these logs so that: The letter-logs come before all digit-logs. The letter-logs are sor..

[파이썬/알고리즘] Leetcode - 1689. Partitioning Into Minimum Number Of Deci-Binary Numb
알고리즘/LeetCode 2021. 6. 28. 15:00

[문제] A decimal number is called deci-binary if each of its digits is either 0 or 1 without any leading zeros. For example, 101 and 1100 are deci-binary, while 112 and 3001 are not. Given a string n that represents a positive decimal integer, return the minimum number of positive deci-binary numbers needed so that they sum up to n. [예시] Example 1: Input: n = "32" Output: 3 Explanation: 10 + 11 + ..

[자바스크립트/알고리즘] Leetcode - 부분 배열의 최대합
알고리즘/LeetCode 2021. 3. 13. 01:04

[문제] 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. [예시] Input Output [-2,1,-3,4,-1,2,1,-5,4] 6 [1] 1 [5,4,-1,7,8] 23 [풀이] var maxSubArray = function(nums) { for(let i = 1; i < nums.length; i++){ nums[i] = Math.max(nums[i], nums[i]+nums[i-1]); } return Math.max(...nums) }; 반복문을 돌면서 nums..

[자바스크립트/알고리즘] LeetCode - 회문 정수
알고리즘/LeetCode 2021. 3. 7. 23:05

[문제] 9. Palindrome Number Given an integer x, return true if x is palindrome integer. An integer is a palindrome when it reads the same backward as forward. For example, 121 is palindrome while 123 is not. [예시] Input Output 121 true -121 false 10 false -101 false [풀이] 프리코드캠프에서 풀었던 회문 문제와 거의 동일하다. [자바스크립트/알고리즘] 회문(Palindrome) 검사 문제 주어진 문자열이 회문이면 true를 반환, 아니면 false를 반환하다. 영숫자가 아닌 문자들(non-alphanum..

[자바스크립트/알고리즘] LeetCode - 정렬된 두 리스트 합치기
알고리즘/LeetCode 2021. 3. 7. 22:57

[문제] 21. Merge Two Sorted Lists 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. [예시] Input Output l1 = [1,2,4], l2 = [1,3,4] [1,1,2,3,4,4] l1 = [], l2 = [] [] l1 = [], l2 = [0] [0] [풀이] /** * Definition for singly-linked list. * function ListNode(val, next) { * this.val = (val===undefined ? 0 : val) * th..