1 2 3 4 5 6 | def listfind(nums:list)->int: for i in range(len(nums)): for j in range(len(nums))[i:]: if nums[j]==nums and j!=i: return True return False |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | import unittest from four import listfind class TestCae(unittest.TestCase): def setUp(self) -> None: pass def tearDown(self) -> None: pass def testone(self): reslt=listfind([]) self.assertFalse(reslt) def testtwo(self): reslt=listfind([1]) self.assertFalse(reslt) def testthree(self): reslt=listfind([1,1]) self.assertTrue(reslt) if __name__=="__main__": unittest.main() |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public class Four { public boolean find(List<Integer> list) { for (int a = 0; a < list.size(); a++) { for (int b = a; b < list.size(); b++) { if (list.get(a).equals(list.get(b)) && !new Integer(a).equals(new Integer(b))) { return true; } } } return false; } } |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |