A group of continuous data. After the order is disrupted, a number is randomly taken out and the retrieved number is searched (solved) in the simplest way)

Source: Internet
Author: User

1. For a group of continuous data, after the order is disrupted, a number is randomly taken out (after a number is taken out, all the digits after the position are moved forward by one digit ), find the number in the simplest way.

2. for expansion of 1, when multiple data items are taken out, the easiest way is to find the number.

I began to abstract the scenario 1 into a general model, jumped into the thinking trap, and figured it out. I was dizzy ....

You can also try to write it first. The following code is not the best (pure test code) and serves only as a reference.

The code for 1 is as follows:

? FindDeletedOneElement (totalLength, firstValue, (totalLength <= [] array = length = [] arrayCopy = randomIndex = random. next (deletedValue = arrayResultLength = (index =; index <length; index ++ (index <-= + = List <> () {deletedValue },FindDeletedOneElement

The code for 2 is as follows:

IList <> FindDeletedElements (totalLength, firstValue, exchangeCount, (totalLength <= [] array = length = [] arrayCopy =? [] ArrayFilled =? (Index =; index <array. length; index ++ currentValue = position = currentValue-= <> deletedValues = List <> (index =; index <length; index ++ (arrayFilled [index] = +FindDeletedElements

All code is as follows:

Main (firstValue =-totalLength =, IList <> FindDeletedElements (totalLength, firstValue, exchangeCount, (totalLength <= [] array = length = [] arrayCopy =? [] ArrayFilled =? (Index =; index <array. length; index ++ currentValue = position = currentValue-= <> deletedValues = List <> (index =; index <length; index ++ (arrayFilled [index] ==+ DeleteData ([] array, (array = | array. length = | count <| count> = (index =; index <count; index ++ randomIndex = random. next (? FindDeletedOneElement (totalLength, firstValue, (totalLength <= [] array = length = [] arrayCopy = randomIndex = random. next (deletedValue = arrayResultLength = (index =; index <length; index ++ (index <-= + = List <> () {deletedValue}, Output (IList <> deletedValues, (deletedValues === (value + Exchange ([] array, (array = | array. length <= | count <= (index =; index <count; index ++ startIndex = randomIndex. next (endIndex = randomIndex. next (startIndex = tempValue = DeleteRandomIndexData ([] array, (array = length = (randomIndex <| randomIndex> = (index = randomIndex; index <length -; index ++ = array [index + = array. take (length-[] CreateArray (count, (count <= [[] array = (index =; index <count; index ++ = ++Program

Everyone has good ideas to write and learn...

Related Article

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.