![](https://img-blog.csdnimg.cn/20210513190848542.jpeg?x-oss-process=image/resize,m_fixed,h_224,w_224)
算法刷题
在leetcode刷题中我认为一些不错的题目的解法
爱笑的李小帅
学了java两年,自我感觉还是小白,请各位大佬多多指教
展开
-
Leetcode 43. 字符串相乘
package leetcode; /** * @Author ****** * @Date 2021/6/8 17:27 * @Param 字符串相乘 */ public class Leetcode43 { public static void main(String[] args) { String num1 = "123", num2 = "456"; String multiply = multiply(num1, num2); S原创 2021-06-08 19:05:52 · 92 阅读 · 0 评论 -
Leetcode 38. 外观数列
本人认为这道题目是一道经典的递归回溯问题,我也是从这道题开始入门的 注释已在代码中 public class Leetcode38 { public static void main(String[] args) { String s = countAndSay(4); System.out.println(s); } public static String countAndSay(int n) { if (n == 1) {原创 2021-06-08 11:38:14 · 58 阅读 · 0 评论 -
Leetcode 15. 三数之和
class Solution { public List<List<Integer>> threeSum(int[] nums) { int len = nums.length; List<List<Integer>> res = new ArrayList<>(); if (len == 0 || len < 3) return res; Arrays.sort(nu原创 2021-06-04 21:30:54 · 50 阅读 · 0 评论 -
Leetcode11. 盛最多水的容器
第一种解法(我最喜欢的一种) class Solution { public int maxArea(int[] height) { int len = height.length; if (len < 2) return 0; int max = 0; int minNum = 0; for (int i = 0; i < len; i++) { for (int j = i + 1原创 2021-06-04 14:42:18 · 43 阅读 · 0 评论 -
leetcode5. 最长回文子串
class Solution { int[] res = new int[2]; public String longestPalindrome(String s) { int n = s.length(); if(n == 0||n == 1){ return s; } char[] ss = s.toCharArray(); for(int i =0;i<n;i++){原创 2021-06-03 17:44:20 · 53 阅读 · 0 评论 -
合并两个有序链表
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * }原创 2021-06-01 10:25:13 · 50 阅读 · 0 评论 -
青蛙跳台阶问题
class Solution { public int numWays(int n) { if(n==0||n==1){ return 1; } int[] arr = new int[n+1]; arr[0] =1; arr[1] = 1; for(int i = 2;i<=n;i++){ arr[i] = (arr[i-1]+arr[i-2])%1原创 2021-05-30 19:01:29 · 55 阅读 · 0 评论 -
二进制中1的个数
public class Solution { // you need to treat n as an unsigned value public int hammingWeight(int n) { int res = 0; while (n != 0) { res += n & 1; n >>>= 1; } return res; } }原创 2021-05-30 18:52:39 · 45 阅读 · 0 评论 -
剑指 Offer 12. 矩阵中的路径
package www; public class Test6 { public boolean exist(char[][] board, String word) { if (board == null || board.length == 0 || word == null) { return false; } char[] chars = word.toCharArray(); boolean[][]原创 2021-05-30 18:43:01 · 65 阅读 · 0 评论 -
MYSQL中的case函数使用
case函数和我们学的java中的 if(){ }else{ } 很像,意思相同 case中的语法格式为 case…when…then…else…end 其中case后面为字段的名称 when 后面为字段里的内容 then 为当符合条件时… else 为当不符合条件时… 例如 select e.date ,round( avg(case e.type when'completed' then 0 else 1 end),3) from email e where e.send_id not in原创 2021-05-21 20:09:33 · 266 阅读 · 0 评论 -
MYSQL中的round函数
1、round(x,d) ,x指要处理的数,d是指保留几位小数 2、round(x) ,其实就是round(x,0),也就是默认d为0; 同时,round()函数中还能附带其他函数,如:sum(),avg(),count()… 例如 select e.date ,round( avg(case e.type when'completed' then 0 else 1 end),3) from email e where e.send_id not in (select id from user w原创 2021-05-21 20:02:11 · 3281 阅读 · 0 评论