diff --git a/src/easy/read_binary_watch.py b/src/easy/read_binary_watch.py new file mode 100644 index 0000000..077569a --- /dev/null +++ b/src/easy/read_binary_watch.py @@ -0,0 +1,24 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +""" + @author: loopgan + @contact: ganwei4955@gmail.com + @time: 18-10-10 上午12:24 +""" + + +class Solution: + def readBinaryWatch(self, num): + """ + :type num: int + :rtype: List[str] + """ + return ['%d:%02d' % (h, m) for h in range(12) for m in range(60) if (bin(h) + bin(m)).count('1') == num] + + +if __name__ == "__main__": + num = 1 + ss = Solution() + print(ss.readBinaryWatch(num)) + # print("Hello imp") diff --git a/src/easy/rotate_string.py b/src/easy/rotate_string.py new file mode 100644 index 0000000..a679f71 --- /dev/null +++ b/src/easy/rotate_string.py @@ -0,0 +1,40 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +""" + @author: loopgan + @contact: ganwei4955@gmail.com + @time: 18-10-10 上午12:58 +""" + + +class Solution: + def rotateString(self, A, B): + """ + :type A: str + :type B: str + :rtype: bool + """ + if len(A) != len(B): + return False + else: + if len(A) == 0: + return True + for i in range(len(B), 0, -1): + if i == 0: + return False + if B[0:i] in A: + if B[i:] in A: + return True + else: + return False + else: + return False + + +if __name__ == "__main__": + A = 'abcde' + B = 'cdeab' + ss = Solution() + print(ss.rotateString(A, B)) + print("Hello imp") diff --git a/src/easy/set_mismatch.py b/src/easy/set_mismatch.py new file mode 100644 index 0000000..da92970 --- /dev/null +++ b/src/easy/set_mismatch.py @@ -0,0 +1,29 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +""" + @author: loopgan + @contact: ganwei4955@gmail.com + @time: 18-9-5 上午12:01 +""" + + +class Solution: + def findErrorNums(self, nums): + tmp = [i + 1 for i in range(len(nums))] + r = 0 + zz = [] + for i in nums: + if i in zz: + r = i + else: + zz.append(i) + lack = list(set(tmp).difference(set(nums)))[0] + return r, lack + + +if __name__ == "__main__": + s = [1, 2, 2, 4] + ss = Solution() + print(ss.findErrorNums(s)) + print("Hello imp")