[LeetCode] 1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence - Python
·
알고리즘/LeetCode
난이도: Easy문제 설명Given a sentence that consists of some words separated by a single space, and a searchWord, check if searchWord is a prefix of any word in sentence.Return the index of the word in sentence (1-indexed) where searchWord is a prefix of this word. If searchWord is a prefix of more than one word, return the index of the first word (minimum index). If there is no such word return -1.A pr..
[LeetCode] 1346. Check If N and Its Double Exist - Python
·
알고리즘/LeetCode
난이도: Easy문제 설명Given an array arr of integers, check if there exist two indices i and j such that :i != j0 arr[i] == 2 * arr[j] 문제 예제Example 1:Input: arr = [10,2,5,3]Output: trueExplanation: For i = 0 and j = 2, arr[i] == 10 == 2 * 5 == 2 * arr[j] Example 2:Input: arr = [3,1,7,11]Output: falseExplanation: There is no i and j that satisfy the conditions. 제한 사항2 -10^3  ✏️ Solution(솔루션)class Solutio..
[Programmers] 섬 연결하기 - Python
·
알고리즘/프로그래머스
난이도: Lv.3 문제 설명개의 섬 사이에 다리를 건설하는 비용(costs)이 주어질 때, 최소의 비용으로 모든 섬이 서로 통행 가능하도록 만들 때 필요한 최소 비용을 return 하도록 solution을 완성하세요. 다리를 여러 번 건너더라도, 도달할 수만 있으면 통행 가능하다고 봅니다. 예를 들어 A 섬과 B 섬 사이에 다리가 있고, B 섬과 C 섬 사이에 다리가 있으면 A 섬과 C 섬은 서로 통행 가능합니다. 제한 사항섬의 개수 n은 1 이상 100 이하입니다.costs의 길이는 ((n-1) * n) / 2이하입니다.임의의 i에 대해, costs[i][0] 와 costs[i] [1]에는 다리가 연결되는 두 섬의 번호가 들어있고, costs[i] [2]에는 이 두 섬을 연결하는 다리를 건설할 때 드는..
[Programmers] 도넛과 막대 그래프 - Python
·
알고리즘/프로그래머스
난이도: Lv.2문제 설명도넛 모양 그래프, 막대 모양 그래프, 8자 모양 그래프들이 있습니다. 이 그래프들은 1개 이상의 정점과, 정점들을 연결하는 단방향 간선으로 이루어져 있습니다.크기가 n인 도넛 모양 그래프는 n개의 정점과 n개의 간선이 있습니다. 도넛 모양 그래프의 아무 한 정점에서 출발해 이용한 적 없는 간선을 계속 따라가면 나머지 n-1개의 정점들을 한 번씩 방문한 뒤 원래 출발했던 정점으로 돌아오게 됩니다. 도넛 모양 그래프의 형태는 다음과 같습니다.크기가 n인 막대 모양 그래프는 n개의 정점과 n-1개의 간선이 있습니다. 막대 모양 그래프는 임의의 한 정점에서 출발해 간선을 계속 따라가면 나머지 n-1개의 정점을 한 번씩 방문하게 되는 정점이 단 하나 존재합니다. 막대 모양 그래프의 형태..
[LeetCode] 3243. Shortest Distance After Road Addition Queries I - Python
·
알고리즘/LeetCode
난이도: medium 문제 설명You are given an integer n and a 2D integer array queries. There are n cities numbered from 0 to n - 1. Initially, there is a unidirectional road from city i to city i + 1 for all 0  queries[i] = [ui, vi] represents the addition of a new unidirectional road from city ui to city vi. After each query, you need to find the length of the shortest path from city 0 to city n - 1. Retu..
[LeetCode] 2924. Find Champion II - Python
·
알고리즘/LeetCode
난이도: Medium 문제 설명There are n teams numbered from 0 to n - 1 in a tournament; each team is also a node in a DAG. You are given the integer n and a 0-indexed 2D integer array edges of length m representing the DAG, where edges[i] = [ui, vi] indicates that there is a directed edge from team ui to team vi in the graph. A directed edge from a to b in the graph means that team a is stronger than team ..