实在太落后了。看了解法还是不会写。 Design an algorithm to print all permutations of a string. For simplicity, assume all characters are unique. Test String: abcdefg Case “a” --> {a} Case “ab” --> {ab, ba} Case “abc” --> ? This is the first “interesting” case. If we had the answer to P(“ab”), how could we generate P(“abc”). Well, the additional letter is “c”, so we can just stick c in at every possible point. That is: merge(c, ab) --> cab, acb, abc merge(c, ba) --> cba, bca, bac Algorithm: Use a recursive algorithm. Generate all permutations of a string by “chopping off” the last character and generating all permutations of s[ 1… n-1]. Then, insert s[n] into every location of the string.
z*q
3 楼
能更猥琐一点吗
h*i
4 楼
The simplest method is by recursion: if you have k letters, then print the first letter, call the function on the remaining (k-1) letters; then second letter, and so on.
obviously. you have no idea about scala. null is java thing
【在 l*****a 的大作中提到】 : whether null is supported in this language? : whether null.permutation is legal?
l*a
14 楼
anything can match null in scala?
【在 p*****2 的大作中提到】 : : obviously. you have no idea about scala. null is java thing
n*r
15 楼
有落后了 what is scala: Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages, enabling Java and other programmers to be more productive. Code sizes are typically reduced by a factor of two to three when compared to an equivalent Java application.
【在 n******r 的大作中提到】 : 有落后了 : what is scala: : Scala is a general purpose programming language designed to express common : programming patterns in a concise, elegant, and type-safe way. It smoothly : integrates features of object-oriented and functional languages, enabling : Java and other programmers to be more productive. Code sizes are typically : reduced by a factor of two to three when compared to an equivalent Java : application.
【在 n******r 的大作中提到】 : 实在太落后了。看了解法还是不会写。 : Design an algorithm to print all permutations of a string. For simplicity, : assume all characters are unique. : Test String: abcdefg : Case “a” --> {a} : Case “ab” --> {ab, ba} : Case “abc” --> ? : This is the first “interesting” case. If we had the answer to P(“ab”), : how could we generate P(“abc”). Well, the additional letter is “c”, so : we can just stick c in at every possible point. That is: