头像

Egbert-Lannister.




离线:6小时前


最近来访(137)
用户头像
qinsishi
用户头像
Wd1335032864
用户头像
聖鋆
用户头像
Aurora_qjy
用户头像
misaka545
用户头像
xcb
用户头像
H_z_xiao
用户头像
UoU
用户头像
kingsfkjaoqmmszrqia
用户头像
无_900
用户头像
tonngw
用户头像
不拿周赛牌不改名
用户头像
钱余多
用户头像
凡事都可破
用户头像
波澜
用户头像
撒野_9
用户头像
反向折叠的千纸鹤
用户头像
lanqiaobeizmy
用户头像
xYang_a0a1
用户头像
Clean_up_the_stupid_incra


/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public void deleteNode(ListNode node) {
        ListNode next = node.next;
        node.val = next.val;
        node.next = next.next;
    }
}


活动打卡代码 AcWing 84. 求1+2+…+n

class Solution {
    public int getSum(int n) {
        if(n==1) return n;
        return n + getSum(n-1);
    }
}


活动打卡代码 AcWing 16. 替换空格

class Solution {
    public String replaceSpaces(StringBuffer str) {
        return str.toString().replace(" ","%20");
    }
}


活动打卡代码 AcWing 21. 斐波那契数列

class Solution {
    public int Fibonacci(int n) {
        if(n<=1) return n;
        return Fibonacci(n-1) + Fibonacci(n-2);
    }
}


活动打卡代码 AcWing 823. 排列

import java.util.Scanner;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;

public class Main {
    private static int[] path;
    private static boolean[] st;
    private static int n;
    private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

    private static void dfs(int u) throws Exception {
        if (u == n) {
            for (int i = 0; i < n; i ++ )
                bw.write(path[i] + 1 + " ");
            bw.write("\n");
        } else {
            for (int i = 0; i < n; i ++ )
                if (!st[i]) {
                    path[u] = i;
                    st[i] = true;
                    dfs(u + 1);
                    st[i] = false;  // 恢复现场
                }
        }
    }

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        path = new int[n];
        st = new boolean[n];

        dfs(0);

        bw.flush();
    }
}


活动打卡代码 AcWing 822. 走方格

import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        System.out.println(dfs(n,m));
    }
    public static int dfs(int n,int m){
        if( n==0 && m==0 ) return 1;
        if( n<0 || m<0 ) return 0;
        return dfs(n-1,m)+dfs(n,m-1);
    }
}


活动打卡代码 AcWing 821. 跳台阶

import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(dfs(n));
    }
    public static int dfs(int n){
        if( n==0 ) return 1;
        int res = dfs(n-1);
        if(n>=2) res+=dfs(n-2);
        return res;
    }
}


活动打卡代码 AcWing 818. 数组排序

import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt(), r = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0;i < n; i++){
            a[i] = sc.nextInt();
        }
        sort(a,l,r);
        for(int i = 0;i<n;i++){
            System.out.printf("%d ",a[i]);
        }
    }
    public static void sort(int a[], int l, int r){
        for (int i = l; i <= r; i ++ ) {
            for (int j = i; j <= r; j ++ ) {
                if (a[j] < a[i]) {
                    int t = a[j];
                    a[j] = a[i];
                    a[i] = t;
                }
            }
        }
    }
}


活动打卡代码 AcWing 817. 数组去重

import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0;i < n; i++){
            a[i] = sc.nextInt();
        }
        System.out.println(get_unique_count(a,n));
    }
    public static int get_unique_count(int a[], int n){
        int sum = 0;
        for (int i = 0; i < n; i ++ ) {
            boolean flag = true;
            for (int j = 0; j < i; j ++ ) {
                if (a[j] == a[i]) {
                    flag = false;
                    break;
                }
            }
            if (flag) sum ++ ;
        }

        return sum;
    }
}


活动打卡代码 AcWing 816. 数组翻转

import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), size = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0;i<n;i++){
            a[i] = sc.nextInt();
        }
        reverse(a,size);
        for(int i = 0;i<n;i++){
            System.out.printf("%d ",a[i]);
        }
    }
    public static void reverse(int[] a, int size){
        for(int i = 0, j = size - 1;i<j;i++,j--){
            int t = a[i];
            a[i] = a[j];
            a[j] = t;
        }
    }
}