[Swift] anagrams group

September 05, 2017 0 Comments


// Given an array of words, print all anagrams together. For example, if the given array is {“cat”, “dog”, “tac”, “god”, “act”}, then output may be “cat tac act dog god”.

說明:給一個String array, 把裡面字串相同字的group在一起後輸出。
解法: 
1. Put source array in to set A
2. for loop every element in the string array if element's sorted char is equal first element. If found put into an array B.
3. remove set A's element same in the array B and put it to for loop function again.


0 comments: