本文整理汇总了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))
示例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'))
示例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'))
示例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'))
示例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))
示例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("", []))
示例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())
示例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"))
示例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()
示例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)
示例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"}))
示例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))
示例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"))
示例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"))
示例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))