개요
날짜 2022.12.04 일 11:30 ~ 13:00
링크: https://leetcode.com/contest/weekly-contest-322/
결과 3 / 4
1. Circular Sentence
링크: https://leetcode.com/contest/weekly-contest-322/problems/circular-sentence/
반복문 사용
class Solution:
def isCircularSentence(self, sentence: str) -> bool:
# 1. init
s = sentence.split(" ")
# 2. loop
prev = s[-1]
for c in s:
if prev[-1] != c[0]:
return False
prev = c
return True
2. Divide Players Into Teams of Equal Skill
링크: https://leetcode.com/contest/weekly-contest-322/problems/divide-players-into-teams-of-equal-skill/
투포인터 사용
class Solution:
def dividePlayers(self, skill: List[int]) -> int:
# 1. init
res = 0
# 2. sort
skill.sort()
# 3. loop
l, r = 0, len(skill) - 1
sum_skill = skill[l] + skill[r]
while l < r:
if skill[l] + skill[r] != sum_skill:
return -1
res += skill[l] * skill[r]
l += 1
r -= 1
return res
3. Minimum Score of a Path Between Two Cities
링크: https://leetcode.com/contest/weekly-contest-322/problems/minimum-score-of-a-path-between-two-cities/
다익스트라 사용
class Solution:
def minScore(self, n: int, roads: List[List[int]]) -> int:
# 1. init
MAX_INT = int(1e14)
d = [MAX_INT] * (n+1)
v = [[] for _ in range(n+1)]
# 2. make graph
for s, e, c in roads:
v[s].append((e, c))
v[e].append((s, c))
# 3. dijkstra
def dijkstra(start_node):
pq = []
heappush(pq, (d[start_node], start_node))
while pq:
cost, node = heappop(pq)
if d[node] < cost:
continue
for n_node, n_cost in v[node]:
cost = min(cost, n_cost)
if d[n_node] > cost:
d[n_node] = cost
heappush(pq, (d[n_node], n_node))
dijkstra(1)
return d[n]
4. Divide Nodes Into the Maximum Number of Groups
못품
무슨 문제인지도 모르겠습니다.
'leetcode - contest' 카테고리의 다른 글
weekly-contest-323 (0) | 2022.12.11 |
---|---|
weekly-contest-321 (0) | 2022.12.04 |