150強訪談簡單

合併三元組

「合併三元組」問題的詳細指南和 Python 實作。

問題陳述

簡單

三元組是三個整數的陣列。給定一個 2D 整數數組三元組,其中 Triplets[i] = [ai, bi, ci] 描述第 i 個三元組。您還會得到一個整數陣列 target = [x, y, z] 來描述您想要得到的三元組。如果可以取得目標三元組 [x, y, z] 作為三元組的元素,則傳回 True,否則傳回 False。

寫一個函數 mergeTriplets(triplets: List[List[int]], target: List[int]) -> bool

約束條件
  • 1 <= len(triplets) <= 10^5
  • triplets[i].length == target.length == 3
  • 1 <= ai, bi, ci, x, y, z <= 1000

範例

Example 1
Input
triplets = [[2,5,3],[1,8,4],[1,7,5]], target = [2,7,5]
Output
True
Explanation

Merge [2,5,3] and [1,7,5] to get [max(2,1), max(5,7), max(3,5)] = [2,7,5].

Example 2
Input
triplets = [[3,4,5],[4,5,6]], target = [3,2,5]
Output
False
Explanation

Cannot get index 1 value of 2.

Need a Hint?
考慮使用特定於貪婪的資料結構,例如集合或堆疊。
Edge Cases to Watch
  • 空輸入結構
  • 單元素輸入
  • 大數值範圍

準備好解決了嗎?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

在編輯器中開啟
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

推薦的 Python 資源

透過相關的互動式教學、備忘單和程式碼比較來擴展您的知識。