Weikoi

导航

2020年8月5日 #

__init__.py 文件的作用与运行的时间点

摘要: Python的package需要有一个区别于普通的directory的标志,这个标志就是根目录下是否有__init__.py文件。 __init__.py文件中的代码运行时间是导入包时,见示例代码: print("flag1") from Pkg1.file1 import demo_func1 p 阅读全文

posted @ 2020-08-05 14:11 Weikoi 阅读(860) 评论(0) 推荐(0) 编辑

Jetbrains IDE快捷键记录

摘要: 从网上找了一下Pycharm的常用快捷键,最常用的加粗显示,方便以后用,Jetbrains真是一家伟大的公司,IDE都做的超级好用! 编辑类: Ctrl + Space 基本的代码完成(类、方法、属性)Ctrl + Alt + Space 类名完成Ctrl + Shift + Enter 语句完成C 阅读全文

posted @ 2020-08-05 09:41 Weikoi 阅读(220) 评论(0) 推荐(0) 编辑

2020年3月9日 #

Leetcode-018-四数之和

摘要: 和三数之和思路一样,先排序,再双指针。 class Solution { public List<List<Integer>> fourSum(int[] nums, int target) { Arrays.sort(nums); List<List<Integer>> res = new Arr 阅读全文

posted @ 2020-03-09 23:40 Weikoi 阅读(109) 评论(0) 推荐(0) 编辑

Leetcode-017-电话号码的字母组合

摘要: 全排列问题。 class Solution { public List<String> letterCombinations(String digits) { Map<Character, String> dict = new HashMap<>(); dict.put('2', "abc"); d 阅读全文

posted @ 2020-03-09 01:30 Weikoi 阅读(140) 评论(0) 推荐(0) 编辑

2020年3月6日 #

Leetcode-016-最接近的三数之和

摘要: 先排序,然后双指针。 class Solution { public int threeSumClosest(int[] nums, int target) { int res = nums[0]+nums[1]+nums[2]; Arrays.sort(nums); for(int i=0;i<n 阅读全文

posted @ 2020-03-06 14:30 Weikoi 阅读(118) 评论(0) 推荐(0) 编辑

Leetcode-015-三数之和

摘要: 先排序,再用双指针,注意的是解中是没有重复的情况的,所以需要跳过。 class Solution { public List<List<Integer>> threeSum(int[] nums) { List<List<Integer>> res = new ArrayList<>(); Arra 阅读全文

posted @ 2020-03-06 00:32 Weikoi 阅读(109) 评论(0) 推荐(0) 编辑

2020年3月5日 #

Leetcode-014-最长公共前缀

摘要: 本题比较简单,遍历就好,o(M*N)时间复杂度,遍历终止的条件是长度到头或者某一位字符互不相等。 class Solution { public String longestCommonPrefix(String[] strs) { if(strs.length==0)return ""; for( 阅读全文

posted @ 2020-03-05 15:11 Weikoi 阅读(91) 评论(0) 推荐(0) 编辑

2020年3月4日 #

Leetcode-013-罗马数字转整数

摘要: 双指针问题,当前的数小于后一位,就减去它的值,否则就加上它的值。 class Solution { public int romanToInt(String s) { Map<Character, Integer> demo = new HashMap<>(); demo.put('I', 1); 阅读全文

posted @ 2020-03-04 23:54 Weikoi 阅读(99) 评论(0) 推荐(0) 编辑

Leetcode-012-整数转罗马数字

摘要: 贪心算法,表达的种类是有穷尽的,从大到小进行贪心就好。 class Solution { public String intToRoman(int num) { int[] nums= new int[]{1000,900,500,400,100,90,50,40,10,9,5,4,1}; Stri 阅读全文

posted @ 2020-03-04 13:09 Weikoi 阅读(85) 评论(0) 推荐(0) 编辑

2020年2月22日 #

Leetcode-011-盛最多水的容器

摘要: 本题的暴力法不难,难的是 O(n) 的方法。 移动的策略是每次向内移动较短的那一端,为什么呢,因为如果向内移动长的那一端面积一定减少,但是移动短的那一端存在面积变大的可能性。 关键的关键就是向内移动长的那端面积一定见少,这样思路就明确了。 class Solution { public int ma 阅读全文

posted @ 2020-02-22 21:34 Weikoi 阅读(88) 评论(0) 推荐(0) 编辑