All the Matches of the League — LeetCode 2339 Python Solution
EasyLeetCode PremiumDatabase
- Problem
- #2339
- Reading time
- 2 min
- Source
- leetcode.com
Table schema
SQL
Table: Teams +-------------+---------+ | Column Name | Type | +-------------+---------+ | team_name | varchar | +-------------+---------+ team_name is the column with unique values of this table. Each row of this table shows the name of a team.Example
SQL
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| team_name | varchar |
+-------------+---------+
team_name is the column with unique values of this table.
Each row of this table shows the name of a team.Python solution
Python
import duckdb
import pandas as pd
def solution(teams: pd.DataFrame) -> pd.DataFrame:
con = duckdb.connect()
con.register("Teams", teams)
return con.execute("""SELECT t1.team_name AS home_team, t2.team_name AS away_team
FROM
Teams AS t1
JOIN Teams AS t2
WHERE t1.team_name != t2.team_name;""").df()Complexity
| Measure | Complexity |
|---|---|
| Time | O(n log n) (typical) |
| Space | O(n) auxiliary |
Related problems
Frequently asked questions
- How hard is LeetCode 2339. All the Matches of the League?
- LeetCode 2339. All the Matches of the League is rated Easy on LeetCode.
- What topics does LeetCode 2339. All the Matches of the League cover?
- LeetCode 2339. All the Matches of the League is tagged Database on LeetCode.
- Is LeetCode 2339. All the Matches of the League a premium problem?
- Yes. LeetCode 2339. All the Matches of the League is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.