Software Engineering Personal Assignment 07

Source: Internet
Author: User

I. Design ideas

1. Remove two different IDs from the list each time by looking for them (regardless of whether they contain "water king" id)

2. It was concluded that the number of occurrences was still more than half ID

Two. Code implementation

public class Shuiwang {public static void main (string[] args) {//TODO auto-generated method stubint[] array={5,1,2,3,8,5, 5,5,5,4,5}; System.out.println (Find (array));} public static int Find (int[] array) {int m=array.length;int n=0;int a=0;for (int i=0;i<m;i++) {if (a==0) {n=array[i];a=1 ;} Else{if (N==array[i]) {++a;} else{--a;}}} return n;}}

  

Three. Implement

Four. Personal summary

I use this algorithm has a disadvantage, do not know exactly How many times this ID appears, can only know that the number of occurrences of the ID more than half , If you want to know, and finally to traverse several times.

Through this class test, I know it is not difficult to make, but to use the best way is that we should consider learning.

Software Engineering Personal Assignment 07

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.