- 博客(53)
- 收藏
- 关注
原创 python爬虫-网易云音乐的歌曲热评
爬虫小白在b站看的视频教程,爬取的是网易云音乐的歌曲热评。本文仅用于学习记录,不用作任何商业用途。本文最后附带源代码和运行效果图。1.安装库import requestsfrom Crypto.Cipher import AESfrom base64 import b64encodeimport json这里有一个小坑,就是这个Crypto。如果电脑中的site-packages中已经带有crypto的话,先把它删除!然后我们再通过pip install pycryptodome来安装
2021-07-05 17:33:22 1369 2
原创 java LintCode 627.最长回文串
1.题目2.解法①字符串、哈希表+循环public class Solution { public int longestPalindrome(String s) { int res = 0; int n = s.length(); if(n == 0) return 0; int flag = 0; Map<Character, Integer> map = new HashMap<>(
2021-06-29 19:56:44 191
原创 java LintCode 90.k数和(二)
1.题目2.解法①一维数组+dfspublic class Solution { public List<List<Integer>> kSumII(int[] A, int k, int target) { List<List<Integer>> res = new ArrayList<>(); List<Integer> temp = new ArrayList<>();
2021-06-28 01:39:51 239
原创 java LintCode 363.接雨水
1.题目2.解法①一维数组+双指针public class Solution { public int trapRainWater(int[] heights) { int res = 0; int l = 0; int r; int n = heights.length; for(int i = 0; i < n; i++){ if(heights[i] != 0){
2021-06-22 13:15:14 176
原创 java LintCode 437.书籍复印
1.题目2.解法①二维数组+动态规划public class Solution { public int copyBooks(int[] pages, int k) { int n = pages.length; if(n == 0) return 0; if(k > n) k = n; int[][] dp = new int[k+1][n+1]; int[] sums = new int[n+
2021-06-17 11:06:00 197
原创 java LintCode 25.打印X
1.题目2.解法①可变字符串+循环public class Solution { public List<String> printX(int n) { List<String> res = new ArrayList<>(); int l = 0; int r = n - 1; while(l < n && r >= 0){ St
2021-06-15 20:12:19 176
原创 java 力扣 646.最长数对链
1.题目2.解法①一维数组+排序、动态规划class Solution { public int findLongestChain(int[][] pairs) { int n = pairs.length; int[] dp = new int[n]; Arrays.fill(dp, 1); Arrays.sort(pairs, (a, b) -> (a[0] - b[0])); for(in
2021-06-14 23:50:07 1497 8
原创 java 力扣 300.最长递增子序列
1.题目2.解法①一维数组+动态规划class Solution { public int lengthOfLIS(int[] nums) { int n = nums.length; if(n == 0) return 0; int[] dp = new int[n]; dp[0] = 1; int res = 1; for(int i = 1; i < n; i++){
2021-06-11 09:38:48 194 4
原创 java 力扣343.整数拆分
1.题目2.解法①一维数组+动态规划class Solution { public int integerBreak(int n) { if(n == 2) return 1; if(n == 3) return 2; int[] dp = new int[n + 1]; for(int i = 2; i <= n; i++){ dp[i] = i; for(int j =
2021-06-08 19:47:37 260
原创 java 力扣 221.最大正方形
1.题目2.解法①二维数组+动态规划class Solution { public int maximalSquare(char[][] matrix) { if(matrix.length == 0 || matrix[0].length == 0) return 0; int r = matrix.length; int c = matrix[0].length; int[][] dp = new int[r][c];
2021-06-08 17:26:39 193
原创 java 力扣 198.打家劫舍
1.题目2.解法①一维数组+动态规划class Solution { public int rob(int[] nums) { int n = nums.length; if(n == 1) return nums[0]; if(n == 2) return Math.max(nums[0], nums[1]); int[] dp = new int[n]; dp[0] = nums[0]; d
2021-06-08 10:26:58 280
原创 java 力扣 91.解码方法
1.题目2.解法①一维数组+动态规划class Solution { public int numDecodings(String s) { int n = s.length(); int[] dp = new int[n]; if(s.charAt(0) == '0') return 0; dp[0] = 1; for(int i = 1; i < n; i++){ if(s.c
2021-06-07 10:19:42 190
原创 java 力扣 322.零钱兑换
1.题目2.解法①一维数组+动态规划class Solution { public int coinChange(int[] coins, int amount) { int[] dp = new int[amount + 1]; Arrays.fill(dp, Integer.MAX_VALUE); dp[0] = 0; for(int i = 0; i < amount; i++){ if(d
2021-06-06 21:17:57 154
原创 java 力扣 417.太平洋大西洋水流问题
Enable GingerCannot connect to Ginger Check your internet connectionor reload the browserDisable in this text fieldRephraseRephrase current sentence2Log in to edit with Ginger×
2021-06-01 15:01:31 177
原创 java 力扣 93.复原IP地址
Enable GingerCannot connect to Ginger Check your internet connectionor reload the browserDisable in this text fieldRephraseRephrase current sentence2Log in to edit with Ginger×
2021-06-01 12:40:57 159
原创 java 力扣 40.组合
Enable GingerCannot connect to Ginger Check your internet connectionor reload the browserDisable in this text fieldRephraseRephrase current sentence2Log in to edit with Ginger×
2021-05-31 10:41:13 144
原创 java 力扣 77.组合
1.题目2.解法①集合+dfsclass Solution { public List<List<Integer>> combine(int n, int k) { List<List<Integer>> res = new ArrayList<>(); List<Integer> temp = new ArrayList<>(); dfs(1, k, n, te
2021-05-27 17:56:12 210
原创 java 力扣 200.岛屿数量
1.题目2.解法①二维数组+DFSclass Solution { public int numIslands(char[][] grid) { if(grid.length == 0 || grid[0].length == 0){ return 0; } int res = 0; int row = grid.length; int col = grid[0].length;
2021-05-24 13:12:17 218
原创 java 力扣 102.二叉树的层序遍历
1.题目2.解法①队列+BFSclass Solution { public List<List<Integer>> levelOrder(TreeNode root) { // BFS List<List<Integer>> res = new ArrayList<List<Integer>>(); if(root == null){ r
2021-05-23 20:18:34 185
原创 java 力扣 78.子集
1.题目2.解法①集合+深度优先搜索class Solution { public List<List<Integer>> subsets(int[] nums) { List<List<Integer>> res = new ArrayList<List<Integer>>(); int n = nums.length; res.add(new ArrayLis
2021-05-23 13:26:57 238
原创 java 力扣 22.括号生成
1.题目2.解法①集合+广度优先搜索class Solution { public List<String> generateParenthesis(int n) { List<String> res = new ArrayList<>(); if (n == 0){ return res; } dfs("", n, n, res); ret
2021-05-22 15:24:29 156
原创 java 力扣 20.有效的括号
题目解法①数组, 字符串 + 循环class Solution { public boolean isValid(String s) { if(s.length() % 2 != 0){ return false; } char[] c = new char[s.length()]; int index = -1; for(int i = 0; i < s.leng
2021-05-05 10:07:22 117
原创 java 力扣 19. 删除链表的倒数第N个节点
题目解法①链表 + 双指针class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { ListNode ret = new ListNode(0); ret.next = head; ListNode start = ret, end = ret; while(n > 0){ end = end.next;
2021-04-22 09:38:50 151
原创 java 力扣 17. 电话号码的字母组合
题目解法①数组, 字符串 + 循环, 递归class Solution { String[] map = { "", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"
2021-04-21 16:06:13 338
原创 java 力扣 15. 三数之和
题目解法①排序, 双指针 + 集合class Solution { public List<List<Integer>> threeSum(int[] nums) { List<List<Integer>> ret = new ArrayList<List<Integer>>(); int len = nums.length; Arrays.sort(nums);
2021-04-20 10:26:49 95
原创 java 力扣 11. 盛最多水的容器
题目解法①数组+双指针import java.lang.Math;class Solution { public int maxArea(int[] height) { int len = height.length; int ret = Math.min(height[0], height[len - 1]) * (len - 1 - 0); int i = 0; int j = len - 1; whil
2021-04-19 21:36:49 95
原创 Java 力扣 剑指 Offer 19. 正则表达式匹配
题目解法①二维数组 + 循环class Solution { public boolean isMatch(String s, String p) { int m = s.length() + 1; int n = p.length() + 1; boolean[][] dp = new boolean[m][n]; dp[0][0] = true; for(int j = 2; j < n; j += 2
2021-04-12 22:39:24 142
原创 java 力扣 5. 最长回文子串
题目解法①暴力法 -> 用两个循环, 判断每个字串是否是回文的, 如果是, 再判断长度, 最后保存下来.②二维数组, 字符串 + 循环class Solution { public String longestPalindrome(String s) { int len = s.length(); String ret = ""; boolean[][] dp = new boolean[len][len]; for(i
2021-04-11 15:31:50 190
原创 java 力扣 4.寻找两个正序数组的中位数
题目解法①数组 + 双指针class Solution { public double findMedianSortedArrays(int[] nums1, int[] nums2) { int[] nums = new int[nums1.length + nums2.length]; int i = 0; int j = 0; int k = 0; while(i < nums1.length ||
2021-04-09 09:23:54 117
原创 java 力扣 3.无重复字符的最长字串
题目解法①字符串, 哈希表 + 循环class Solution { public int lengthOfLongestSubstring(String s) { Map<Character, Integer> hashmap = new HashMap<Character, Integer>(); int ret = 0; int start = 0; int i; for(i =
2021-04-08 13:52:52 123
原创 java 力扣 2.两数相加
题目解法①循环class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { int flag = 0; ListNode head = new ListNode(); ListNode p = head; while(l1 != null || l2 != null){ int t1 = l1 != null ? l1
2021-04-07 22:52:46 164
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人