01/10/2018, 14:59
Hỏi bài tập java
- Given a linked list of digits (values are from 0 to 9), write a method find the minimum possible sum of two numbers formed from digits of the list. All digits of given list must be used to form the two numbers (4 marks).
Input: [6, 8, 4, 5, 2, 3]
Output: 604
The minimum sum is formed by numbers
358 and 246
Em có một câu bài tập về java mà em chưa hiểu về cái đề với thuật toán cho lắm, mọi người hướng dẫn em với. Cảm ơn ạ
Bài liên quan
Bạn hiểu đề như nào rồi ?
Đề nó nói là sử dụng các chữ số trong danh sách để tạo thành 2 số sao cho tổng của nó là nhỏ nhất có thể. Tất cả các chữ số có trong ds phải được sử dụng.
Giờ ta sắp xếp các chứ số trong list lại từ bé tới lớn 2 3 4 5 6 8, còn 2 số hình thành là 2 4 5; 3 6 8
thử một list khác 1 2 3 4 5 6; 2 số tạo thành là 135; 246
Minh chưa hiểu vể for loai này ak, giải thích giùm mình tí :
for (int x : a)
pq.add(x);
Mình có tham khảo một nguồn trên mạng tạm hiểu rồi ak:
GeeksforGeeks – 19 Dec 16
Minimum sum of two numbers formed from digits of an array - GeeksforGeeks
Given an array of digits (values are from 0 to 9), find the minimum possible sum of two numbers formed from digits of the array.… Read More »
cảm ơn bạn