Created
February 6, 2015 13:19
-
-
Save bongster/fc82c1f648a6933d0cd8 to your computer and use it in GitHub Desktop.
TheNextNumber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getIndex(list: List[List[Int]]) : Int = { | |
0 | |
} | |
val num = "06233" | |
val a = num.split("").sliding(2).toList | |
var index = 0 | |
(a.length -1 to 0 by -1) foreach { n=> | |
val current = a(n).toSeq(1) | |
val next= a(n).toSeq(0) | |
println(s"$n $next $current") | |
if (current >= next){ | |
if (current == next){ | |
index = a.length - n - 1 | |
}else{ | |
index = a.length - n | |
} | |
} | |
} | |
val (b, c) = num.splitAt(index) | |
val convertb = b.last.toString.toInt | |
// c안에서 b.tail보다 큰 수중에 가장 작은 수의 인덱스 | |
val convertc = c.split("").map(_.toInt) | |
val (frontList, backList) = convertc.span(x => { | |
x < convertb | |
}) | |
val result = convertc.find(x => { | |
x < convertb | |
}) match { | |
case Some(findIndex) => "11" | |
case None => b.init + c.last + (c.init + b.last).sorted | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment