- 博客(68)
- 收藏
- 关注
原创 day31-逆波兰表达式(栈)
题目150. 逆波兰表达式求值 - 力扣(LeetCode) (leetcode-cn.com)题解class Solution { public int evalRPN(String[] tokens) {//创建栈 Stack<Integer> stack=new Stack<>();//从左往右遍历 for(int i=0;i<tokens.length;i++){ String curr=tokens[i];
2022-02-11 19:24:43
320
原创 day30-子域名访问计数
题目力扣题解class Solution { public List<String> subdomainVisits(String[] cpdomains) { Map<String,Integer> map=new HashMap<>(); List<String> list=new ArrayList<>(); for(String str:cpdomains){ .
2022-01-28 15:25:11
278
原创 day29-第N位数字
题目给你一个整数 n ,请你在无限的整数序列 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...] 中找出并返回第 n 位上的数字。示例 1:输入:n = 3 输出:3 示例 2:输入:n = 11 输出:0 解释:第 11 位数字在序列 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... 里是 0 ,它是 10 的一部分。提示: 1 <= n <= 231 - 1 第 n 位上的数字是按计数单位(dig
2022-01-27 16:02:17
449
原创 day28-统计隐藏数组
题目力扣题解class Solution { public int numberOfArrays(int[] differences, int lower, int upper) { int[] hidden=new int[differences.length+1]; int count=0; for(int j=lower;j<=upper;j++){ boolean bool=true
2022-01-26 14:49:08
160
原创 day27-按符号重排数组
题目力扣题解class Solution { public int[] rearrangeArray(int[] nums) { int[] temp1=new int[nums.length/2]; int[] temp2=new int[nums.length/2]; int[] target=new int[nums.length]; int m=0; int n=0; for(int
2022-01-26 13:37:57
375
原创 day26-在线选举
题目力扣题解class TopVotedCandidate { // 人获得的票数 Map<Integer,Integer> cntMap = new HashMap<>(); // 当前时间领先的人 TreeMap<Integer,Integer> tm = new TreeMap<>(); public TopVotedCandidate(int[] persons, int[] times) {
2022-01-24 16:04:50
237
原创 day25-求众数
题目力扣题解class Solution { public List<Integer> majorityElement(int[] nums) { List<Integer> list=new ArrayList(); int num=(nums.length)/3; //利用Map Map<Integer,Integer> map=new HashMap<>();
2022-01-18 19:00:51
198
原创 day24-数字转换为十六进制
题目力扣题解 class Solution { public String toHex(int num) { StringBuilder sb=new StringBuilder(); //存储表示0-15的数组 char [] array = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; //临界条件
2022-01-17 16:28:20
369
原创 day23-第三大的数
题目力扣题解class Solution { public int thirdMax(int[] nums) { int max=nums[0]; //未去重前的长度分析 if(nums.length<3){ for(int i=0;i<nums.length;i++){ if(nums[i]>max){ max=nums[i
2022-01-14 19:15:11
139
原创 day22-至少是其他数字两倍的最大数组元素下标
题目力扣题解class Solution { public int dominantIndex(int[] nums) { //实现最大的和次大的进行比较即可 List<Integer> temp=new ArrayList(); for(int i=0;i<nums.length;i++){ temp.add(nums[i]); } if(nums.length=
2022-01-13 18:24:20
57
原创 day-21-递增的三元子序列
题目力扣题解class Solution { public boolean increasingTriplet(int[] nums) { //贪心算法,标记min和mid int min=nums[0]; int mid=Integer.MAX_VALUE; for(int i=0;i<nums.length;i++){ if(nums[i]<min){
2022-01-12 13:21:32
156
原创 day20-全排列
题目力扣题解class Solution { //定义一个属性接收结果集合 private List<List<Integer>> res= new ArrayList<>(); public List<List<Integer>> permute(int[] nums) { //数组为空,返回未初始化的空集合 if (nums.length == 0) {
2022-01-11 20:09:09
88
原创 day19-尽可能使字符串相等
题目描述力扣题解class Solution { public int equalSubstring(String s, String t, int maxCost) { //将对应每个元素开销放到cost数组中 int[] cost=new int[s.length()]; for(int i=0;i<s.length();i++){ int ele=Math.abs(s.charAt(i)-t.charA
2022-01-10 16:16:45
3149
原创 day18-猜数字游戏
题目力扣t题解class Solution { public String getHint(String secret, String guess) { int countA = 0, countB = 0, length = secret.length(); //先判断公牛 for (int i = 0; i < length; i++) { if (secret.charAt(i) == guess.ch
2022-01-07 18:07:07
2223
原创 day17-Z字形变换
题目链接力扣题解class Solution { public static String convert(String s, int numRows) { char[][] array=new char[numRows][s.length()]; int row=-1; int col=0; //作为标志 boolean bool=true; //提交的时候发现的错误,行数等于1时要单独考虑
2022-01-06 17:42:06
391
原创 day16-向字符串添加空格
力扣差点就超时的代码题解class Solution { public String addSpaces(String s, int[] spaces) { //建一个StringBuilder类接收结果 StringBuilder result=new StringBuilder(s); for(int i=0;i<spaces.length;i++){ //调用insert方法,注意插入的位置要加i,插入
2022-01-05 14:19:18
518
原创 day15
题目描述力扣class Solution { public String convertToTitle(int columnNumber) { //26进制!参考十进制转十六进制0~25代表A~Z StringBuilder sb=new StringBuilder(); while(columnNumber>0){ //余数转成字符 int temp=(columnNumber-1)%26
2022-01-04 12:56:56
212
原创 day14
题目描述力扣t题解class Solution { public int[] findErrorNums(int[] nums) { //计数排序 int[] hash=new int[nums.length]; for(int i=0;i<nums.length;i++){ hash[nums[i]-1]++; } int num1=0;//代表重复的元素 i
2022-01-03 14:31:56
123
原创 xml浅学
什么是xmlxml可拓展的标记性语言xml的作用1.保存数据,而且这些数据具有自我描述性2.作为项目或者模块的配置文件3.作为网络传输数据的格式(Json为主)xml语法1.文档声明 <?xml version="1.0" encoding="utf-8" ?>2.xml注释和html一样<!-- -->3.元素:元素是从开始标签到结束标签的部分,元素可以拥有属性 命名规则:名称包含字母数字其他字符;名称不能数字或标点符号开头;名称不能包含空格 也
2022-01-01 20:18:38
261
原创 day13
题目描述力g关于我投机取巧失败那些事单纯想利用stringbuilder的方法,所以就想一一删除每个字符然后调用reverse方法,结果就死在了这个删除字符这条路上,利用什么子串还有什么转字符数组然后要删除的地方换成空格,再转成字符串,还有每一次删除都创建一个stringbuilder,然后调他的删除方法生成一个新的stringbuilder,很遗憾都超出时间限制了,总之api的方法以后要慎用了!!!想到String的replace方法,问了昌神发现replace会把所有的字符都换成另外一个
2021-12-31 16:08:59
198
原创 day12
题目力扣题解class Solution { public int findPoisonedDuration(int[] timeSeries, int duration) { int sum=0; for(int i=0;i<timeSeries.length-1;i++){ if(timeSeries[i+1]>=timeSeries[i]+duration){ sum=sum+du
2021-12-30 20:41:21
487
原创 day11
第一题力扣class Solution { public int[] twoSum(int[] nums, int target) { int i; int j; int num1=0; int num2=0; for(i=0;i<nums.length;i++){ for(j=i+1;j<nums.length;j++){ if(nums[i
2021-12-29 12:28:44
220
原创 MySQL基础学习(一)
os:一直没总结,偷懒直接粘贴当时学的时候记的,有点乱DDL目录os:一直没总结,偷懒直接粘贴当时学的时候记的,有点乱DDL语言库和表的创建修改删除库的创建库的修改库的删除库的修改库的删除表的创建表的修改表的删除表的复制DML语言(很重要!!!)插入语句#删除语句#修改语句语言库和表的创建修改删除库的创建create database (if not exists)库名库的修改在存储位置改就行库的删除..
2021-12-28 20:08:17
341
原创 day10
题目描述给定一个只包含三种字符的字符串:(,)和 *,写一个函数来检验这个字符串是否为有效字符串。有效字符串具有如下规则:任何左括号 (必须有相应的右括号 )。任何右括号 )必须有相应的左括号 (。左括号 ( 必须在对应的右括号之前 )。*可以被视为单个右括号 ),或单个左括号 (,或一个空字符串。一个空字符串也被视为有效字符串。示例 1:输入: "()"输出: True错误尝试计算三者数量,单纯通过数量比较仅能通过部分,左括号必须在右括号前较难实现cl...
2021-12-28 12:23:55
185
原创 day09
题目描述给你一个正整数 n ,生成一个包含 1 到 n的平方 所有元素,且元素按顺时针顺序螺旋排列的 n x n 正方形二维整型数组 matrix ,并将其打印出来.思路图代码public class day9 { public static void main(String[] args) { //测试用例 solution(3); System.out.println("**************"); so
2021-12-27 17:24:28
147
原创 day08
力扣class Solution { public double myPow(double x, int n) { //方法一:return Math.pow(x,n); //方法二:快速幂法 long p = n; p = Math.abs(p); double temp = x; double result = 1; while (p > 0) { i
2021-12-10 19:45:39
509
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人