- 博客(8)
- 收藏
- 关注
原创 打卡四
1.两数之和 class Solution { public int[] twoSum(int[] nums, int target) { for(int i=0;i<nums.length;i++){ for(int j=i+1;j<nums.length;j++) { if(int[i]+int[j]==target) { return new int[]{i,j}; } } } throw new IllegalArgumentException(“No two sum solution”
2020-08-27 19:41:24 154
原创 打卡三
1.搜索插入位置 class Solution { public int searchInsert(int[] nums, int target) { for(int i=0;i<nums.length;i++){ if(target<=nums[i]) return i; } return nums.length; } } 2.快乐数 class Solution { public boolean isHappy(int n) { Set<Integer> hashSet=
2020-08-25 19:28:52 77
原创 打卡二
1.最长回文子串 class Solution: def longestPalindrome(self, s): “”" :type s: str :rtype: str “”" if len(s) < 2 or s == s[::-1]: return s start, maxlength = 0, 1 for i in range(1, len(s)): odd = s[i-maxlength-1:i+1] # 检查l+2 even = s[i-ma
2020-08-22 21:40:01 120
原创 打卡一
Task01:分治 1.Pow(x,n) class Solution: def myPow(self, x, n): if n == 0: return 1 elif n < 0: x = 1/x n = -n ans = 1.0 while n > 0: if n&1 : ans *= x x *= x n >>= 1 return ans 2.最大子序和 class Solution { public: int maxSubArray(vector& nums)
2020-08-18 20:28:32 93
原创 打卡九
1.linux使用’utf-8’编码方式,window使用’GBK’编码方式。平台编码(UTF-8)与window平台(GBK)不一样。可以使用open(encoding=xx)进行转码 2.def longest_word(filename): f = open(filename, ‘r’) max_list = [] count = 0 for each in f: split_list = each.split(’,’) for elem in split_list: if len(elem) >
2020-08-08 17:15:09 78
原创 打卡八
模块 1.可以利用help函数查看function。 2.from collections import Counter def most_element(language): “”" Return a list of lines after inserting a word in a specific line. “”" m=Counter(language) for key,value in m.items(): if(value == max(m.values())): return key lang
2020-08-07 19:58:12 86
原创 打卡7
2.通过在方法名前加_实现定义私有方法,从而使得该方法只能在类内调用。 3.执行结果为: Traceback (most recent call last): File “E:/python3.8.2/1.py”, line 1, in class C: File “E:/python3.8.2/1.py”, line 4, in C c = C() NameError: name ‘C’ is not defined 错误的原因是在定义方法的时候没有加上self参数;可以将def myFun():改为d
2020-08-05 22:18:40 124
原创 打卡六
1.在函数定义下第一行用""进行注释。可以在函数的第一行输入一个字符串,这个字符串就代表了这个函数的注释。 这个对函数的描述被保存在函数的属性里,可以用funcname.__doc__调出来。 2.在函数对应形参后面冒号说明类型,在def的括号后面箭头说明返回值类型。 3.要修改闭包作用域中的变量则需要 nonlocal 关键字,对嵌套外的变量进行声明。 4.a=[[6, 5], [3, 7], [2, 8]] print(a) x = sorted(a, key=lambda a: a[0], rever
2020-08-02 21:51:59 89
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人