diff --git a/.gitignore b/.gitignore index 9d800a9..8b0481f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,237 +1,121 @@ -################# -## Eclipse -################# - -*.pydevproject -.project -.metadata -bin/ -tmp/ -*.tmp *.bak -*.swp -*~.nib -local.properties -.classpath -.settings/ -.loadpath -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# CDT-specific -.cproject - -# PDT-specific -.buildpath - - -################# -## Visual Studio -################# - -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# User-specific files -*.suo -*.user -*.sln.docstates - -# Build results - -[Dd]ebug/ -[Rr]elease/ -x64/ +### Python template +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ build/ -[Bb]in/ -[Oo]bj/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -*_i.c -*_p.c -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.log -*.scc - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opensdf -*.sdf -*.cachefile - -# Visual Studio profiler -*.psess -*.vsp -*.vspx - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -*.ncrunch* -.*crunch*.local.xml - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.Publish.xml -*.pubxml - -# NuGet Packages Directory -## TODO: If you have NuGet Package Restore enabled, uncomment the next line -#packages/ - -# Windows Azure Build Output -csx -*.build.csdef - -# Windows Store app package directory -AppPackages/ - -# Others -sql/ -*.Cache -ClientBin/ -[Ss]tyle[Cc]op.* -~$* -*~ -*.dbmdl -*.[Pp]ublish.xml -*.pfx -*.publishsettings - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file to a newer -# Visual Studio version. Backup files are not needed, because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -App_Data/*.mdf -App_Data/*.ldf - -############# -## Windows detritus -############# - -# Windows image file caches -Thumbs.db -ehthumbs.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Mac crap -.DS_Store - - -############# -## Python -############# - -*.py[co] - -# Packages -*.egg -*.egg-info +develop-eggs/ dist/ -build/ +downloads/ eggs/ +.eggs/ +lib/ +lib64/ parts/ -var/ sdist/ -develop-eggs/ +var/ +*.egg-info/ .installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec # Installer logs pip-log.txt +pip-delete-this-directory.txt # Unit test / coverage reports +htmlcov/ +.tox/ .coverage -.tox +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover -#Translations +# Translations *.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio -#Mr Developer -.mr.developer.cfg -log/ -data/ -# python byte code -*.pyc - -############# -## Sublime -############# -# Ignore production server environment files -uwsgi_params -# sublime text -*.sublime-workspace - - -############# -## Idea -############# -.idea -.idea/ -*.eml *.iml -doc/ \ No newline at end of file +## Directory-based project format: +.idea/ +# if you remove the above rule, at least ignore the following: + +# User-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# .idea/dictionaries + +# Sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml +# .idea/uiDesigner.xml + +# Gradle: +# .idea/gradle.xml +# .idea/libraries + +# Mongo Explorer plugin: +# .idea/mongoSettings.xml + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +### Java template +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + diff --git a/049 Anagrams.py b/049 Anagrams.py index 7f7e636..d1a3f11 100644 --- a/049 Anagrams.py +++ b/049 Anagrams.py @@ -4,6 +4,8 @@ Note: All inputs will be in lower-case. """ __author__ = 'Danyang' + + class Solution: def anagrams_complicated(self, strs): """ @@ -13,13 +15,12 @@ def anagrams_complicated(self, strs): """ temp = list(strs) for ind, string in enumerate(temp): - if string and string!="": # avoid case of empty string + if string and string != "": # avoid case of empty string string = [char for char in string] string.sort() string = "".join(string) temp[ind] = string - hash_map = {} for ind, string in enumerate(temp): indexes = hash_map.get(string, []) @@ -28,7 +29,7 @@ def anagrams_complicated(self, strs): result = [] for val in hash_map.values(): - if len(val)>1: + if len(val) > 1: # result.append([strs[i] for i in val]) result += [strs[i] for i in val] return result @@ -46,16 +47,17 @@ def anagrams(self, strs): hash_map[string] = [ind] else: hash_map[string].append(ind) - # indexes = hash_map.get(string, []) - # indexes.append(ind) # side-effect - # hash_map[string] = indexes # reassign + # indexes = hash_map.get(string, []) + # indexes.append(ind) # side-effect + # hash_map[string] = indexes # reassign result = [] for val in hash_map.values(): - if len(val)>1: + if len(val) > 1: # result.append([strs[i] for i in val]) result += [strs[i] for i in val] return result -if __name__=="__main__": - Solution().anagrams(["", ""]) \ No newline at end of file + +if __name__ == "__main__": + Solution().anagrams(["", ""])