Have just encountered a tricky algorithm problem, solving

Source: Internet
Author: User
Solving


Reply to discussion (solution)

$a = Array (1,2,2,3,1,2,3,1,1), $st = Array (1 = 0), $d = 1;foreach ($a as $v) {  @ $st [$v]++;  if ($v >= $d) {    $d = $v;  } else{    while ($v < $d) {      unset ($st [$d--]);    }  }  
Array
(
[0] = 1
[1] = 1.1
[2] = 1.2
[3] = 1.2.1
[4] = 2
[5] = 2.1
[6] = 2.1.1
[7] = 3
[8] = 4
)

Sorry, I didn't see what it meant. ......。。 ...。 ............。 ......。。 ...。 ......。。 ...。 ......。 ......。 .........

$a = Array (1,2,2,3,1,2,3,1,1), $st = Array (1 = 0), $d = 1;foreach ($a as $v) {  @ $st [$v]++;  if ($v >= $d) {    $d = $v;  } else{    while ($v < $d) {      unset ($st [$d--]);    }  }  
Array
(
[0] = 1
[1] = 1.1
[2] = 1.2
[3] = 1.2.1
[4] = 2
[5] = 2.1
[6] = 2.1.1
[7] = 3
[8] = 4
)


Moderator, thank you for your answer, if so, can you talk about your ideas ah, thank you very much

Sorry, I didn't see what it meant. ......。。 ...。 ............。 ......。。 ...。 ......。。 ...。 ......。 ......。 .........


The topic is actually a directory layout problem, you can see that the priority determines the size of the title of the display

$a = array (1,2,2,3,1,2,3,1,1); Represents the level at which the node is located
$st = Array (1 = 0); Stores the current ordinal number of each layer
$d represents the current level

Well, thanks to the moderator's explanation, I'll do a good research, first to distribute the

  • 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.