Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to arrange the array into the smallest number by python

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to arrange the array into the smallest number by python". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to arrange arrays into the smallest number by python".

Topic description

Enter an array of positive integers, splice all the numbers in the array into a number, and print the smallest of all the numbers that can be concatenated. For example, if you enter an array of {3rec 32321}, the smallest number you can print out of these three numbers is 321323.

Train of thought

Can be seen as a sorting problem, first convert the integer array into the String array, when comparing the size of the two strings o1 and O2, you should compare the size of o1+o2 and o2+o1, if o1+o2 < o2+o1, then o1 should be placed first, otherwise O2 should be placed first.

Code implementation of package Tree

Import java.util.ArrayList

Enter a binary tree and an integer in the binary tree and enter a path for a certain value in the binary tree, and print out all paths where the sum of the node values in the binary tree is the input integer. * the path is defined as a path from the root node of the tree down to the node through which the leaf node passes. * / public class Solution45 {private ArrayList result = new ArrayList (); private ArrayList list = new ArrayList ()

Public ArrayList FindPath (TreeNode root, int target) {if (root = = null) {return result;} list.add (root.val); target-= root.val; if (target = = 0 & & root.left = = null & & root.right = = null) {result.add (new ArrayList (list));} FindPath (root.left, target) FindPath (root.right, target); list.remove (list.size ()-1); return result;}

Public class TreeNode {int val = 0; TreeNode left = null; TreeNode right = null

Public TreeNode (int val) {this.val = val

}

}}

At this point, I believe you have a deeper understanding of "how to arrange the array into the smallest number in python". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report