stuck at 1002
improve performance for 1002

1. use dict to replace instead of regex
2. use loop instead of recurse
3. use class instead of struct ( not much help .... )
more solutions