zoukankan      html  css  js  c++  java
  • 请编写一个函数,其功能为输入一个字符串,打印出该字符串中字符的所有排列

    exchange(str, i, j){
          let arr = str.split("")
          if(str == ""){
            return 
          }else {
            let tmp = arr[i]
            arr[i] = arr[j]
            arr[j] = tmp
          }
          this.str = arr.join("")
          // console.log("str", this.str)
        },
        fullPermutationsOfString(str, begin, end){
          str = this.str
          if(str == "" || begin > end){
            return
          }
          if(begin == end - 1){
            console.log(str)
          }else {
            for(let i = begin; i < end; ++i){
              this.exchange(str, begin, i)
              this.fullPermutationsOfString(str, begin+1, end)
              this.exchange(str, begin, i)
            }
          }
        }
        this.str = "ab"
        let length = this.str.length
        this.fullPermutationsOfString(this.str, 0, length)
  • 相关阅读:
    noip模拟赛#38
    noip模拟赛#45
    noip模拟赛#15
    noip模拟赛#14
    noip模拟赛
    rp++
    bzoj2127: happiness
    bzoj3209:3209: 花神的数论题
    10.1 plan
    FFT
  • 原文地址:https://www.cnblogs.com/sinceForever/p/13463975.html
Copyright © 2011-2022 走看看