Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def duplicateEncode(word: String) = {
- def helper(str:String,i:Int=0,ans:String=""):String=
- {
- if(str.toLowerCase.count(_==str.toLowerCase.charAt(i))>1)
- {
- val strN = ans+")"
- if(i<str.length-1)
- helper(str, i+1, strN)
- else strN
- }
- else {
- val strN = ans+"("
- if(i<str.length-1)
- helper(str, i+1, strN)
- else strN
- }
- }
- helper(word)
- }
- /////////////////////////////////////////////////
- object Solution {
- def duplicateEncode(word: String) = {
- word.toLowerCase.map(c => if (word.toLowerCase.count(_ == c) <= 1) "(" else ")").mkString
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement