算法:返回字符串中不重复的第一个字符串

package algorithm

import java.util

/**
  * Created by angel;
  */
object findStr {

  def main(args: Array[String]): Unit = {
    val str = "dddffffssxsadc"
    val toArray: Array[Char] = str.toArray
    val findOne = iteratorStr(toArray)
    println(findOne)
  }


  //迭代字符串
  def iteratorStr(array: Array[Char]):Char ={
    val store = new util.ArrayList[Integer]()
    val storeDel = new util.HashSet[Integer]()
      for(index <- 0 until array.length){
        val word: Integer = array(index).toInt
        if(storeDel.contains(word)){

        }
        if(store.contains(word)){

          store.remove(word)
          storeDel.add(word)
        }else{
          store.add(word)
        }
      }

    store.get(0).toChar
  }
}

 

posted @ 2019-03-17 17:52  niutao  阅读(503)  评论(0编辑  收藏  举报