NetEase small easy to have a length of n sequence, small easy to remove the inside of the repeated elements, but small easy to think is for each element to retain the last occurrence of the _ Programming train

Source: Internet
Author: User
Import java.util.ArrayList;
Import java.util.List;

Import Java.util.Scanner; /** * Small easy to have a length of n sequence, small easy to remove the inside of the repeating elements, but small easy to think is for each element to retain the last occurrence of that.
 Small easy to meet difficulties, I hope you to help him. * * * * @author pomay * * * * */public class Wangyi_duplicate {public void Slove (int[] sequence) {//define a linked list to store the final result List
		<Integer> list = new arraylist<integer> (); Iterate from the back to ensure that each element retains the last occurrence of the for (int i = sequence.length-1 i >= 0; i--) {//If there is no such number in the list, put in if (!list.contain

		S (Sequence[i]) List.add (Sequence[i]); (int i = List.size ()-1; I >= 0; i--) {if (i > 0) System.out.print (list.get (i) + "")
			;
		Else System.out.print (List.get (i));
		} public static void Main (string[] args) {//input includes two lines: Scanner s = new Scanner (system.in);
		The first behavior sequence length n (1≤n≤50) int n = s.nextint ();
		Second act n number sequence[i] (1≤sequence[i]≤1000), separated by a space int[] sequence = new Int[n];
		for (int i = 0; i < n; i++) {Sequence[i] = S.nextint (); } wangyi_duplicate DuplicatE = new Wangyi_duplicate ();

	Duplicate.slove (sequence);
 }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.