def main(): l1 = ListNode(1) l2 = ListNode(9) l2.next = ListNode(9) s = Solution() s.addTwoNumbers(l1, l2)
class TestCase(unittest.TestCase): def setUp(self): self.sol = Solution() def test_1(self): answer = self.sol.groupAnagrams( ["eat", "tea", "tan", "ate", "nat", "bat"]) expected = [["eat", "tea", "ate"], ["tan", "nat"], ["bat"]] self.assertEqual(answer, expected)
class TestCase(unittest.TestCase): def setUp(self): self.sol = Solution() def test_1(self): answer = self.sol.romanToInt("III") expected = 3 self.assertEqual(answer, expected) def test_2(self): answer = self.sol.romanToInt("IV") expected = 4 self.assertEqual(answer, expected) def test_3(self): answer = self.sol.romanToInt("IX") expected = 9 self.assertEqual(answer, expected) def test_4(self): answer = self.sol.romanToInt("LVIII") expected = 58 self.assertEqual(answer, expected) def test_5(self): answer = self.sol.romanToInt("MCMXCIV") expected = 1994 self.assertEqual(answer, expected) def test_6(self): answer = self.sol.romanToInt("MMMCMXCIX") expected = 3999 self.assertEqual(answer, expected)
class TestCase(unittest.TestCase): def setUp(self): self.sol = Solution() def test_1(self): answer = self.sol.backspaceCompare("ab", "ab") expected = True self.assertEqual(answer, expected) def test_2(self): answer = self.sol.backspaceCompare("ab##", "c#d#") expected = True self.assertEqual(answer, expected) def test_3(self): answer = self.sol.backspaceCompare("a##c", "#ac#c") expected = True self.assertEqual(answer, expected) def test_4(self): answer = self.sol.backspaceCompare("a#c", "b") expected = False self.assertEqual(answer, expected) def test_5(self): answer = self.sol.backspaceCompare("ad#c", "ab#c") expected = True self.assertEqual(answer, expected) def test_6(self): answer = self.sol.backspaceCompare("y#fo##f", "y#fx#o##f") expected = True self.assertEqual(answer, expected)
from sol import Solution num1 = [1, 2, 8, 9] num2 = [5, 6, 8, 1] n = Solution() print(n.findMedianSortedArrays(num1, num2))
def setUp(self): self.sol = Solution()
from sol import Solution soln = Solution() io_pairs = [([10, 9, 2, 5, 3, 7, 101, 18], 4), ([1, 3, 6, 7, 9, 4, 10, 5, 6], 6)] def test_dp_lengthOfLIS(): for nums, ans in io_pairs: assert (soln.dp_lengthOfLIS(nums) == ans) def test_dp_lengthOfLIS_bottom_up(): for nums, ans in io_pairs: assert (soln.dp_lengthOfLIS_bottom_up(nums) == ans)