当前位置: 首页>>代码示例>>Python>>正文


Python LeetSolution.LeetSolution类代码示例

本文整理汇总了Python中LeetSolution.LeetSolution的典型用法代码示例。如果您正苦于以下问题:Python LeetSolution类的具体用法?Python LeetSolution怎么用?Python LeetSolution使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LeetSolution类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_rightSideView

 def test_rightSideView(self):
     s = LeetSolution()
     self.assertEqual([], s.rightSideView(None))
     root = TreeNode.makeTree([1, 2, 3, '#', 5, '#', 4])
     self.assertEqual([1, 3, 4], s.rightSideView(root))
     root = TreeNode.makeTree([1, 2, 3, '#', 5, '#', 4, 6])
     self.assertEqual([1, 3, 4, 6], s.rightSideView(root))
开发者ID:pengmeng,项目名称:LeetCode,代码行数:7,代码来源:test_leetSolution.py

示例2: test_lengthOfLongestSubstring

 def test_lengthOfLongestSubstring(self):
     s = LeetSolution()
     self.assertEqual(0, s.lengthOfLongestSubstring(''))
     self.assertEqual(3, s.lengthOfLongestSubstring('abcabcbb'))
     self.assertEqual(1, s.lengthOfLongestSubstring('bbbbbbb'))
     self.assertEqual(8, s.lengthOfLongestSubstring('qwnfenpglqdq'))
     self.assertEqual(8, s.lengthOfLongestSubstring('qwnfenpglqdq'))
开发者ID:pengmeng,项目名称:LeetCode,代码行数:7,代码来源:test_leetSolution.py

示例3: test_wordPattern

 def test_wordPattern(self):
     s = LeetSolution()
     self.assertTrue(s.wordPattern('abba', 'dog cat cat dog'))
     self.assertFalse(s.wordPattern('abba', 'dog cat cat fish'))
     self.assertFalse(s.wordPattern('aaaa', 'dog cat cat dog'))
     self.assertFalse(s.wordPattern('abba', 'dog dog dog dog'))
     self.assertTrue(s.wordPattern('aaaa', 'dog dog dog dog'))
开发者ID:pengmeng,项目名称:LeetCode,代码行数:7,代码来源:test_leetSolution.py

示例4: test_exist

 def test_exist(self):
     s = LeetSolution()
     board = ["ABCE",
              "SFCS",
              "ADEE"]
     self.assertTrue(s.exist(board, 'ABCCED'))
     self.assertTrue(s.exist(board, 'SEE'))
     self.assertFalse(s.exist(board, 'ABCB'))
开发者ID:pengmeng,项目名称:LeetCode,代码行数:8,代码来源:test_leetSolution.py

示例5: test_searchii

 def test_searchii(self):
     s = LeetSolution()
     self.assertTrue(s.searchii([4, 4, 5, 5, 0, 1, 2, 3, 4], 0))
     self.assertTrue(s.searchii([4, 4, 5, 5, 0, 1, 2, 3, 4], 4))
     self.assertTrue(s.searchii([4, 4, 5, 5, 0, 1, 2, 3, 4], 1))
     self.assertFalse(s.searchii([4, 4, 5, 5, 0, 1, 2, 3, 4], 10))
     self.assertTrue(s.searchii([1, 3, 1, 1, 1], 1))
     self.assertTrue(s.searchii([1, 3, 1, 1, 1], 3))
开发者ID:pengmeng,项目名称:LeetCode,代码行数:8,代码来源:test_leetSolution.py

示例6: test_wordBreak

 def test_wordBreak(self):
     s = LeetSolution()
     in_s = "leetcode"
     in_dict = ["leet", "code"]
     self.assertTrue(s.wordBreak(in_s, in_dict))
     self.assertTrue(s.wordBreak("a", ["a"]))
     self.assertTrue(s.wordBreak("aa", ["a"]))
     self.assertFalse(s.wordBreak("", []))
开发者ID:pengmeng,项目名称:LeetCode,代码行数:8,代码来源:test_leetSolution.py

示例7: test_mergeKLists2

 def test_mergeKLists2(self):
     s = LeetSolution()
     values = [sorted([randint(0, 100) for x in range(0, 50)]) for x in range(0, 7)]
     new = copy.deepcopy(values)
     lists = [ListNode.makeList(value) for value in new]
     result = []
     for v in values:
         result.extend(v)
     result.sort()
     self.assertEqual(result, s.mergeKLists2(lists).toarray())
开发者ID:pengmeng,项目名称:LeetCode,代码行数:10,代码来源:test_leetSolution.py

示例8: test_atoi

 def test_atoi(self):
     s = LeetSolution()
     self.assertEqual(0, s.atoi(""))
     self.assertEqual(1234, s.atoi("1234"))
     self.assertEqual(1234, s.atoi("+1234"))
     self.assertEqual(-1234, s.atoi("-1234"))
     self.assertEqual(1, s.atoi("1"))
     self.assertEqual(0, s.atoi("   a1234"))
     self.assertEqual(1234, s.atoi("   1234  abc"))
     self.assertEqual(-12, s.atoi("  -12a34"))
     self.assertEqual(2147483647, s.atoi("21474836471"))
开发者ID:pengmeng,项目名称:LeetCode,代码行数:11,代码来源:test_leetSolution.py

示例9: test_removeNthFromEnd

 def test_removeNthFromEnd(self):
     s = LeetSolution()
     head = ListNode.makeList([1, 2, 3, 4, 5])
     s.removeNthFromEnd(head, 2).show()
     head = ListNode.makeList([1, 2])
     s.removeNthFromEnd(head, 1).show()
     head = ListNode.makeList([1])
     print(s.removeNthFromEnd(head, 1))
     head = ListNode.makeList([1, 2])
     s.removeNthFromEnd(head, 2).show()
     head = ListNode.makeList([1, 2, 3])
     s.removeNthFromEnd(head, 3).show()
开发者ID:pengmeng,项目名称:LeetCode,代码行数:12,代码来源:test_leetSolution.py

示例10: test_solve

 def test_solve(self):
     s = LeetSolution()
     board = ['XXXX',
              'XOOX',
              'XXOX',
              'XOXX']
     after = ['XXXX',
              'XXXX',
              'XXXX',
              'XOXX']
     s.solve(board)
     self.assertEqual(after, board)
开发者ID:pengmeng,项目名称:LeetCode,代码行数:12,代码来源:test_leetSolution.py

示例11: test_findLadders

 def test_findLadders(self):
     s = LeetSolution()
     print(s.findLadders('hit', 'cog', {"hot", "dot", "dog", "lot", "log"}))
     print(s.findLadders("qa",
                         "sq",
                         {"si", "go", "se", "cm", "so", "ph", "mt", "db", "mb", "sb", "kr", "ln", "tm", "le",
                          "av", "sm", "ar", "ci", "ca", "br", "ti", "ba", "to",
                          "ra", "fa", "yo", "ow", "sn", "ya", "cr", "po", "fe", "ho", "ma", "re", "or", "rn",
                          "au", "ur", "rh", "sr", "tc", "lt", "lo", "as", "fr",
                          "nb", "yb", "if", "pb", "ge", "th", "pm", "rb", "sh", "co", "ga", "li", "ha", "hz",
                          "no", "bi", "di", "hi", "qa", "pi", "os", "uh", "wm", "an", "me", "mo", "na", "la",
                          "st", "er", "sc", "ne", "mn", "mi", "am", "ex", "pt", "io", "be", "fm", "ta", "tb",
                          "ni", "mr", "pa", "he", "lr", "sq", "ye"}))
开发者ID:pengmeng,项目名称:LeetCode,代码行数:13,代码来源:test_leetSolution.py

示例12: test_searchMatrix

 def test_searchMatrix(self):
     s = LeetSolution()
     self.assertTrue(s.searchMatrix([[1, 3, 5, 7],
                                     [10, 11, 16, 20],
                                     [23, 30, 34, 50]], 3))
     self.assertFalse(s.searchMatrix([[1, 3, 5, 7],
                                      [10, 11, 16, 20],
                                      [23, 30, 34, 50]], -1))
     self.assertTrue(s.searchMatrix([[1, 3, 5, 7],
                                     [10, 11, 16, 20],
                                     [23, 30, 34, 50]], 10))
     self.assertFalse(s.searchMatrix([[1, 3, 5, 7],
                                      [10, 11, 16, 20],
                                      [23, 30, 34, 50]], 100))
开发者ID:pengmeng,项目名称:LeetCode,代码行数:14,代码来源:test_leetSolution.py

示例13: test_strstrsd

 def test_strstrsd(self):
     s = LeetSolution()
     self.assertEqual(2, s.strstrsd("ababac", "abac"))
     self.assertEqual(-1, s.strstrsd("", "abc"))
     self.assertEqual(0, s.strstrsd("abc", ""))
     self.assertEqual(0, s.strstrsd("", ""))
     self.assertEqual(2, s.strstrsd("bcbcdef", "bcd"))
     self.assertEqual(2, s.strstrsd("ababac", "abac"))
     self.assertEqual(-1, s.strstrsd("mississippi", "issipi"))
     self.assertEqual(-1, s.strstrsd("mississippi", "a"))
     self.assertEqual(1, s.strstrsd("mississippi", "issi"))
开发者ID:pengmeng,项目名称:LeetCode,代码行数:11,代码来源:test_leetSolution.py

示例14: test_numDecodings2

 def test_numDecodings2(self):
     s = LeetSolution()
     self.assertEqual(0, s.numDecodings2(""))
     self.assertEqual(0, s.numDecodings2("0"))
     self.assertEqual(0, s.numDecodings2("00"))
     self.assertEqual(0, s.numDecodings2("100"))
     self.assertEqual(1, s.numDecodings2("101"))
     self.assertEqual(1, s.numDecodings2("10"))
     self.assertEqual(1, s.numDecodings2("8"))
     self.assertEqual(2, s.numDecodings2("12"))
     self.assertEqual(3, s.numDecodings2("1234"))
开发者ID:pengmeng,项目名称:LeetCode,代码行数:11,代码来源:test_leetSolution.py

示例15: test_numIslands

 def test_numIslands(self):
     s = LeetSolution()
     self.assertEqual(0, s.numIslands([]))
     grid = [['1', '1', '1', '1', '0'],
             ['1', '1', '0', '1', '0'],
             ['1', '1', '0', '0', '0'],
             ['0'] * 5]
     self.assertEqual(1, s.numIslands(grid))
     grid = [['1', '1', '0', '0', '0'],
             ['1', '1', '0', '0', '0'],
             ['0', '0', '1', '0', '0'],
             ['0', '0', '0', '1', '1']]
     self.assertEqual(3, s.numIslands(grid))
     grid = [['0'] * 5] * 5
     self.assertEqual(0, s.numIslands(grid))
开发者ID:pengmeng,项目名称:LeetCode,代码行数:15,代码来源:test_leetSolution.py


注:本文中的LeetSolution.LeetSolution类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。