Guest User

Untitled

a guest
Jul 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. class Solution:
  2. def findWords(self, words):
  3. """
  4. :type words: List[str]
  5. :rtype: List[str]
  6. """
  7. # judge which row the input char belongs to
  8. def judgeRow(c):
  9. row1 =['q','w','e','r','t','y','u','i','o','p','Q','W','E','R','T','Y','U','I','O','P']
  10. row2 =['a','s','d','f','g','h','j','k','l','A','S','D','F','G','H','J','K','L']
  11. row3 =['z','x','c','v','b','n','m','Z','X','C','V','B','N','M']
  12. if(row1.count(c)):
  13. return 1
  14. elif(row2.count(c)):
  15. return 2
  16. else:
  17. return 3
  18.  
  19. listReturn = [] # to store the final retured list, outside the loop
  20. for word in words:
  21. wordRecover = ''
  22. rowNum = judgeRow(word[0]) # judge the row from the first char
  23. #print (rowNum)
  24. for c in word:
  25. rowCurrent = judgeRow(c)
  26. print (rowCurrent)
  27. if(rowCurrent != rowNum):
  28. wordRecover = ''
  29. break;
  30. wordRecover += c
  31. print (wordRecover)
  32. if(wordRecover!=''):
  33. listReturn.append(wordRecover)
  34. return listReturn
Add Comment
Please, Sign In to add comment