大家好 有題屬於"簡易"的襪子題 想問問這solution code的解題邏輯 因為是看得懂code 但不懂為何此題這樣寫(或者正確是 不太清楚這題該怎麼解) 謝謝大家~ 大感謝! John works at a clothing store. He has a large pile of socks that he must pair by color for sale. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are. for example, there are n=7 socks with colors ar=[1,2,1,2,1,3,2] There is one pair of color 1 and one pair of color 2. The number of pairs is 2. Solution code: def sockMerchant(n, ar): count=0 ar.sort() ar.append('#') i=0 while i < n: if ar[i]==ar[i+1]: count=count+1 i+=2 else: i+-=1 return count 我能了解if statement上半部 如果i和i+1相同顏色 則pair count+1 但else就不太能理解 還有arr.append('#')的作用 謝謝大家了!