GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — algorithms/backtrack/permute_unique.py at master · RajaRamu/algorithms Expand file tree/ Copy pathpermute_unique.pyMore file actions 24 lines (20 loc) · 549 Bytes / Copy pathpermute_unique.pyFile metadata and controls24 lines (20 loc) · 549 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 # Given a collection of numbers that might contain duplicates, # return all possible unique permutations. # For example, # [1,1,2] have the following unique permutations: # [ # [1,1,2], # [1,2,1], # [2,1,1] # ] def permute_unique(nums): perms = [[]] for n in nums: new_perms = [] for l in perms: for i in range(len(l)+1): new_perms.append(l[:i]+[n]+l[i:]) if i<len(l) and l[i]==n: break #handles duplication perms = new_perms return perms |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |