목록Python (55)
복's
https://leetcode.com/problems/same-tree/description/ Same Tree - LeetCode Can you solve this real interview question? Same Tree - Given the roots of two binary trees p and q, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical, and the nodes have the leetcode.com 주어진 트리가 동일한 트리인지 비교하는 문제로 나는 트리를 순회하면서 매번 트리의 노드가 갖는 va..
https://leetcode.com/problems/binary-tree-inorder-traversal/ Binary Tree Inorder Traversal - LeetCode Can you solve this real interview question? Binary Tree Inorder Traversal - Given the root of a binary tree, return the inorder traversal of its nodes' values. Example 1: [https://assets.leetcode.com/uploads/2020/09/15/inorder_1.jpg] Input: root = [1,nu leetcode.com 트리가 주어지고 중위 순회하며 요소를 출력하는 문제이..
https://leetcode.com/problems/merge-sorted-array/description/ Merge Sorted Array - LeetCode Can you solve this real interview question? Merge Sorted Array - 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 an leetcode.com 정석적인 풀이는 두 배열의 인덱스를 2개 만들고, 삽입할 위치의..
https://leetcode.com/problems/remove-duplicates-from-sorted-list/description/ Remove Duplicates from Sorted List - LeetCode Can you solve this real interview question? Remove Duplicates from Sorted List - Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well. Example 1: [https://assets.le leetcode.com 생각보다 자주..
https://leetcode.com/problems/sqrtx/description/ Sqrt(x) - LeetCode Can you solve this real interview question? Sqrt(x) - Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well. You must not use any built-in exponent function or o leetcode.com 문제 푸는데 시간은 많이 안걸렸는데 내 코드는 시간이 오래 걸려서 보니까 다른 풀이 방법은 내가 생각하지 못..
https://www.acmicpc.net/problem/11286 11286번: 절댓값 힙 첫째 줄에 연산의 개수 N(1≤N≤100,000)이 주어진다. 다음 N개의 줄에는 연산에 대한 정보를 나타내는 정수 x가 주어진다. 만약 x가 0이 아니라면 배열에 x라는 값을 넣는(추가하는) 연산이고, x가 0 www.acmicpc.net 힙을 사용하는 문제였는데 힙의 구현을 유도하는 문제였나 싶다. 힙은 사실 아직까지 구현 해본적 없어서 해보긴 해야 하는데.... [ 📌 풀이 ] 정수가 1개씩 주어지는데 1개씩 주어질 때마다 분기 요구사항에 맞춰서 처리하면 된다. 0일 때 heap이 비어있다면 0을 출력한다. heap이 비어있지 않다면 요소 하나 출력한다. 0이 아닐 때 힙에 주어진 정수를 넣는다. 다만 정수..
https://leetcode.com/problems/add-binary/description/ Add Binary - LeetCode Can you solve this real interview question? Add Binary - Given two binary strings a and b, return their sum as a binary string. Example 1: Input: a = "11", b = "1" Output: "100" Example 2: Input: a = "1010", b = "1011" Output: "10101" Constraints: * leetcode.com 문제 보고서 제공되는 라이브러리 사용해서 그냥 넘어가고싶은 마음이 굴뚝 같았다 ㅋㅋㅋ.. 그래도 대충 어떻..
https://www.acmicpc.net/problem/2559 2559번: 수열 첫째 줄에는 두 개의 정수 N과 K가 한 개의 공백을 사이에 두고 순서대로 주어진다. 첫 번째 정수 N은 온도를 측정한 전체 날짜의 수이다. N은 2 이상 100,000 이하이다. 두 번째 정수 K는 합을 구하기 www.acmicpc.net 백준도 풀어줘야할 것 같아서 백준도 브론즈 ~ 실버만 정글 나만무 기간에 풀기로 결심했다. 오늘 다시 한 번 놀란건 6개월을 자바로 알고리즘 연습 했는데 답안 제출하니까 에러가 많이 떴다는거? [ 📌 풀이 ] 1) 주어진 배열에 대한 구간합 배열을 생성 2) 주어진 K의 개수만큼의 합을 확인해서 ans(정답) max 값으로 갱신 구간합 개념만 알면 어렵지 않게 풀 수 있는 문제였다. ..
https://leetcode.com/problems/plus-one/description/ Plus One - LeetCode Can you solve this real interview question? Plus One - You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to- leetcode.com 파이썬과 자바의 차이에 대해서 느끼게 되는 문제였다. [ 📌 틀린 이유 ] python의 경우에는 알..
https://leetcode.com/problems/length-of-last-word/ Length of Last Word - LeetCode Can you solve this real interview question? Length of Last Word - Given a string s consisting of words and spaces, return the length of the last word in the string. A word is a maximal substring consisting of non-space characters only. Example 1: Input: leetcode.com 문자열 기본 문제로 크게 고민하지 않았다. 하지만 java 문자열 구하는 법에 대해서 3..
