刷刷刷 2026/7/16

1.

进制转换_牛客题霸_牛客网

java 复制代码
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String a = in.nextLine();
        char[] chars = a.substring(2, a.length()).toCharArray();
        int n = 0;
        int sum = 0;
        for (int i = chars.length - 1; i >= 0; i--) {
            if (chars[i] >= 'A' && chars[i] <= 'F') {
                sum += (chars[i] - 'A' + 10) * Math.pow(16, n);
            } else {
                sum += (chars[i] - '0') * Math.pow(16, n);
            }
            n++;
        }
        System.out.println(sum);
    }
}

两数之和_牛客题霸_牛客网

java 复制代码
import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param numbers int整型一维数组 
     * @param target int整型 
     * @return int整型一维数组
     */
    public int[] twoSum (int[] numbers, int target) {
        // write code here
        int arr[]=new int[2];
        for (int i = 0; i < numbers.length-1; i++) {
            for (int j = i+1; j < numbers.length; j++) {
                if (numbers[i]+numbers[j]==target){
                    arr[0]=i+1;
                    arr[1]=j+1;
                    return arr;
                }
            }
        }
        return arr;
    }
}

暴力枚举,超时了......

明明的随机数_牛客题霸_牛客网

java 复制代码
import java.util.HashSet;
import java.util.Scanner;
import java.util.TreeSet;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        int arr[]=new int[n];
        TreeSet set=new TreeSet<>();
        for (int i = 0; i < n; i++) {
            arr[i]=in.nextInt();
            set.add(arr[i]);
        }
        Object[] array = set.toArray();
        for (int i = 0; i < set.size(); i++) {
            System.out.println(array[i]);
        }
    }
}

直接拿集合了

跳台阶_牛客题霸_牛客网

java 复制代码
import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param number int整型
     * @return int整型
     */
    public int jumpFloor (int number) {
        // write code here
        //第n个格子的跳法=第n-1个格子的跳法+第n-2个格子的跳法
        //f[2]=f[1]+f[0]
        //f[0]=1
        //f[1]=1
        if (number==0||number==1){
            return 1;
        }else {
            return jumpFloor(number-1)+jumpFloor(number-2);
        }
    }
}

最简单递归,秒了


hhhhh不用刷了来不及了hhhhh

相关推荐
sharemylove17 小时前
Java集合框架全面详解
java·开发语言·经验分享·笔记·学习
whyTeaFo17 小时前
GAMES202: Lecture 3: Real-Time Shadows 1 ppt笔记
笔记
摇滚侠19 小时前
《On Java 中文版 基础卷》阅读笔记 内部类 20
java·笔记·python
旖旎夜光1 天前
LeetCode 493: 翻转对 (归并排序) —— 题解
c++·笔记·学习·算法·leetcode·排序算法
吃我一窝jio1 天前
Java IO流核心分类与应用
java·开发语言·笔记
Uio2411 天前
Java HashMap 底层原理详解(JDK1.8 优化、哈希冲突、红黑树、面试必问)
笔记
inferno1 天前
Java正则表达式学习笔记
java·笔记·学习·正则表达式
小李不想当小白1 天前
HAL库之中断(STM32 HAL库学习笔记)
笔记·stm32·单片机·嵌入式硬件·学习·嵌入式
Uio2411 天前
Java集合:ArrayList与LinkedList核心对比(实战+源码要点)
笔记
旖旎夜光1 天前
面试题 01.02: 判定是否互为字符重排 (哈希表) —— 题解
c++·笔记·学习·算法·哈希表