반응형

아리니의 삶 87

[LeetCode 리트코드] Merge Sorted ArraySolution

문제 Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. The number of elements initialized in nums1 and nums2 are m and n respectively. You may assume that nums1 has enough space (size that is equal to m + n) to hold additional elements from nums2. (해설) integer 어레이 nums1과 nums2을 nums1에 합쳐서 정렬하라. nums1의 요소 개수는 m, num2의 요소 개수는 n이다. nums1의 길이는 m+n이다. 예 input ..

[LeetCode 리트코드] Check If Two String Arrays are Equivalent, python3, 파이썬

문제 string리스트 word1과 word2가 주어진다. 이 리스트들을 모두 합쳤을 때 두 개가 같으면 true, 다르면 false를 리턴하라. 예 input : word1 = ["ab", "c"], word2 = ["a", "bc"] output : true input : word1 = ["a", "cb"], word2 = ["ab", "c"] output : false 추가사항 word1과 wor2의 길이는 10^3이하. 각 리스트에 있는 문자열의 길이도 10^3 이하. 각 리스트의 문자열을 다 합친 길이도 10^3 이하. 나의 솔루션 class Solution: def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool: ..

[LeetCode 리트코드] Longest Substring Without Repeating Characters , python3

문제 문자열 s가 주어진다. s의 substring중에서 중복된 문자가 없는 substring의 최대 길이를 리턴하라. 예 input : s = "abcabcbb" output : 3 추가사항 0 한국어 번역) The naive approach is very straightforward. But it is too slow. So how can we optimize it? -> 단순한 접근은 상당히 직관적이지만 매우 느리다. 어떻게 최적화할 수 있는가? In the naive approaches, we repeatedly check a substring to see if it has duplicate character. But it is unnecessary. If a substring s[i:j]​ fr..

[LeetCode 리트코드] Find a Corresponding Node of a Binary Tree in a Clone of That Tree

문제 바이너리 트리 original이 주어진다. 그리고 그것의 레퍼런스 버전인 cloned가 주어진다. target노드가 head가 되는 cloned된 트리를 리턴하라. 언뜻 보면 되게 간단하다. 그냥 bfs로 돌면서 target과 value가 같은 노드가 있으면 리턴하면 된다. 예 추가사항 노드의 개수는 1개 이상 10^4개 이하 target 노드는 무조건 original 중에 있음 나의 솔루션 # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None def bfs(node: TreeNode, val): if node.va..

[LeetCode 리트코드] Kth Missing Positive Number

문제 리스트로 주어지는 arr를 제외하고 없는 k번째 숫자를 구하여라. (모든 수는 자연수) 예 input : arr = [1, 2, 5, 6, 7, 10, 20], k = 5 output : 11 1번째 missing number : 3 2번째 missing number : 4 3번째 missing number : 8 4번째 missing number : 9 5번째 missing number : 11 추가사항 arr의 길이는 1000. arr의 요소는 1이상 1000이하, k는 1이상 1000이하. arr는 오름차순 정렬 나의 솔루션 class Solution: def findKthPositive(self, arr: List[int], k: int) -> int: arrIdx = 0 arrLen = l..

Day2 | 간단한 계산기

뼈대코드 아래 다운받기 혹은 복사하여 붙여넣기 ''' 계산기 1. 입력값(input_num)은 숫자(0 - 9)와 사칙연산자(+, -, *, / )이고, 코드에서 주어집니다. 2. 각 숫지/문자는 띄어쓰기로 구분됩니다. (예) 1 + 2 * 5 - 8 3. 사칙연산의 규칙에 따라 곱셈과 나눗셈을 먼저 계산합니다. 4. 정답을 print 하면 됩니다. 5. 단, 0으로 나누는 경우는 없습니다. * 심화 * 1. 숫자가 10 이상인 수도 입력값으로 받을 수 있게 업그레이드 하세요 2. 숫자가 음수일 수 있도록 업그레이드 하세요 ''' input_num = '3 + 5 * 7 - 9 / 3' #심화1 #input_num = '24 * 4 + 1000 / 25 - 3' #심화2 #input_num = '93 +..

[Flutter | 플러터] 함수로 위젯 표현하기 ( audioplayers package)

하나씩 누를 때 실로폰처럼 소리가 나는 앱이다. import 'package:flutter/material.dart'; import 'package:audioplayers/audio_cache.dart'; void main() => runApp(XylophoneApp()); class XylophoneApp extends StatelessWidget { final player = AudioCache(); void playSound(int soundNum) { player.play('note$soundNum.wav'); } Widget buildKey(int numKey, Color _color) { return Expanded( child: FlatButton( onPressed: () { playSou..

반응형