일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- concurrency
- 30. Substring with Concatenation of All Words
- 시바견
- 715. Range Module
- iterator
- Protocol
- LeetCode
- Convert Sorted List to Binary Search Tree
- Python Implementation
- Python Code
- 109. Convert Sorted List to Binary Search Tree
- 운영체제
- Regular Expression
- t1
- 43. Multiply Strings
- data science
- attribute
- shiba
- Substring with Concatenation of All Words
- Class
- Generator
- Decorator
- 밴픽
- 315. Count of Smaller Numbers After Self
- DWG
- Python
- kaggle
- 프로그래머스
- 컴퓨터의 구조
- 파이썬
Archives
- Today
- Total
Scribbling
[Programmers] 순위 본문
https://school.programmers.co.kr/learn/courses/30/lessons/49191#qna
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1. Python
def solution(n, results):
graph = [[0] * n for _ in range(n)]
for u, v in results:
u -= 1
v -= 1
graph[u][v] = 1
for k in range(n):
for u in range(n):
for v in range(n):
if graph[u][k] == 1 and graph[k][v] == 1:
graph[u][v] = 1
ret = 0
for i in range(n):
cnt = 0
cnt += sum(graph[i])
cnt += sum(graph[j][i] for j in range(n))
if cnt == n - 1:
ret += 1
return ret
2. C++
#include <string>
#include <vector>
using namespace std;
int solution(int n, vector<vector<int>> results) {
int graph[n][n];
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
graph[i][j] = 0;
}
}
for (auto result : results) {
int u = result[0], v = result[1];
graph[--u][--v] = 1;
}
for (int k=0; k<n; k++) {
for (int u=0; u<n; u++) {
for (int v=0; v<n; v++) {
if (graph[u][k] == 1 and graph[k][v] ==1) {
graph[u][v] = 1;
}
}
}
}
int ret = 0;
for (int i=0; i<n; i++) {
int cnt = 0;
for (int j=0; j<n; j++) {
cnt += graph[i][j];
}
for (int j=0; j<n; j++) {
cnt += graph[j][i];
}
if (cnt == n - 1) ret ++;
}
return ret;
}
'Computer Science > Algorithms & Data Structures' 카테고리의 다른 글
[LeetCode] 2340. Minimum Adjacent Swaps to Make a Valid Array (0) | 2024.07.02 |
---|---|
[Programmers] 방의 개수 (0) | 2024.07.02 |
[Programmers] 가장 먼 노드 (0) | 2024.06.28 |
[Programmers] 입국심사 (0) | 2024.06.27 |
[Programmers] 징검다리 (0) | 2024.06.27 |