- Today
- Total
목록leetcode (186)
작심삼일
문제 링크: https://leetcode.com/problems/complement-of-base-10-integer/ 문제 The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation. For example, The integer 5 is "101" in binary and its complement is "010" which is the integer 2. Given an integer n, return its complement. 조건 0 int: if n == 0: return 1 ans = 0 cur = 1 wh..
문제 링크: https://leetcode.com/problems/find-the-town-judge/ 문제 In a town, there are n people labeled from 1 to n. There is a rumor that one of these people is secretly the town judge. If the town judge exists, then: The town judge trusts nobody. Everybody (except for the town judge) trusts the town judge. There is exactly one person that satisfies properties 1 and 2. You are given an array trust w..
문제 링크: https://leetcode.com/problems/smallest-integer-divisible-by-k/ 문제 Given a positive integer k, you need to find the length of the smallest positive integer n such that n is divisible by k, and n only contains the digit 1. Return the length of n. If there is no such n, return -1. Note: n may not fit in a 64-bit signed integer. 조건 1
문제 링크: https://leetcode.com/problems/populating-next-right-pointers-in-each-node/ 문제 You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition: struct Node { int val; Node *left; Node *right; Node *next; } Populate each next pointer to point to its next right node. If there is no next right node, th..
문제 링크: https://leetcode.com/problems/merge-intervals/ 문제 Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input. 조건 1
문제 링크: https://leetcode.com/problems/number-complement/ 문제 The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation. For example, The integer 5 is "101" in binary and its complement is "010" which is the integer 2. Given an integer num, return its complement. 조건 1 int: ans = 0 cur = 1 while num > 1: a, b = num//2, nu..
문제 링크: https://leetcode.com/problems/course-schedule-ii/ 문제 There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai. For example, the pair [0, 1], indicates that to take course 0 you have to first take course 1. Retu..
문제 링크: https://leetcode.com/problems/reorder-list/ 문제 You are given the head of a singly linked-list. The list can be represented as: L0 → L1 → … → Ln - 1 → Ln Reorder the list to be on the following form: L0 → Ln → L1 → Ln - 1 → L2 → Ln - 2 → … You may not modify the values in the list's nodes. Only nodes themselves may be changed. 조건 The number of nodes in the list is in the range [1, 5 * 104]..