競賽程式設計簡單

由數字組成的最小和

「數字形成的最小和」問題的詳細指南和 Python 實作。

問題陳述

簡單

寫一個函數 min_sum_digits(arr),它接受單位數整數 arr (0-9) 的列表,並傳回使用數組中所有數字形成的兩個數字的最小和。

約束條件
  • 2 <= len(arr) <= 30
  • 0 <= arr[i] <= 9

範例

Example 1
Input
min_sum_digits([6, 8, 4, 5, 2, 3])
Output
604
Explanation

The minimum sum is obtained by forming the numbers 246 and 358: 246 + 358 = 604.

Example 2
Input
min_sum_digits([5, 3, 0, 7, 4])
Output
82
Explanation

The minimum sum is obtained by forming the numbers 35 and 47 (or 047): 35 + 47 = 82.

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 資源

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