목록LeetCode 코딩테스트 (34)
무냐의 개발일지
👩💻 문제 Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val.Consider the number of elements in nums which are not equal to val be k, to get accepted, you need to do the following things:Change the array nums such that the first k elements of..
👩💻 문제You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively.Merge nums1 and nums2 into a single array sorted in non-decreasing order.The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a..
👩💻 문제Write a function named stream_max that takes as its input a list of integers (nums). The function should return a list of the same length, where each element in the output list is the maximum number seen so far in the input list.More specifically, for each index i in the input list, the element at the same index in the output list should be the maximum value among the elements at indices..
1. remove(value)remove()는 리스트에서 첫 번째로 등장하는 특정 값을 제거합니다. 해당 값이 리스트에 없으면 ValueError가 발생합니다.# 예시 리스트fruits = ['apple', 'banana', 'cherry', 'banana']# 'banana' 제거fruits.remove('banana')print(fruits) # ['apple', 'cherry', 'banana'] 2. pop(index)pop()는 리스트에서 지정한 인덱스의 요소를 제거하고, 그 요소를 반환합니다. 인덱스를 지정하지 않으면 마지막 요소를 제거하고 반환합니다. 인덱스가 리스트 범위를 벗어나면 IndexError가 발생합니다 # 예시 리스트fruits = ['apple', 'banana', 'ch..

Heap는 BST와 매우 유사하게 생겼다BST가 좌우 기준 대소관계를 정렬했다면, Heaps는 부모 자식 간 대소관계를 정렬했다는 특징이 있다.(Each node has a number that is higher than all of its decendants. So the highest value is always at the top) 특징 3가지!1. Complete tree 이다 (filled from left to right with NO GAPS)2. you can have DUPLICATES! (부모 자식 간 값이 중복 가능하다)(맨 위에 최대/ 최소값이 오느냐에 따라 Max heap, Min heap이 있다.)3. 맨 위가 최대값이라는 거 빼면 좌우 관련 규칙이 없다. 따라서, Heap i..
| 기본구조 class Graph: def __init__(self): self.adj_list = {}그래프는 matrix, list 두가지로 나타낼 수 있는데, time complexity 가 더 효율적인 list로 그려내도록 한다빈 딕셔너리를 만들고 여기에 각 꼭지점을 key로, 연결된 Edges를 values로 나타내도록 한다 | Add Vertex : O(1)def add_vertex(self, vertex): if vertex not in self.adj_list.keys(): self.adj_list[vertex] = [] return True return False 단순 리스트를 append한다이미 있는게 ..
👩💻 문제 몇 번 인덱스에서 몇 번 인덱스까지 더해야 target값이 나오는지, 그 인덱스 쌍을 리스트로 구하는 문제 Given an array of integers nums and a target integer target, write a Python function called subarray_sum that finds the indices of a contiguous subarray in nums that add up to the target sum using a hash table (dictionary).Your function should take two arguments:nums: a list of integers representing the input arraytarget: an in..
👩💻 문제You have been given an array of strings, where each string may contain only lowercase English letters. You need to write a function group_anagrams(strings) that groups the anagrams in the array together using a hash table (dictionary). The function should return a list of lists, where each inner list contains a group of anagrams.For example, if the input array is ["eat", "tea", "tan", "a..