java内部类使用

最近刷力扣时,经常想用c/c++的结构体加sort函数自定义排序(那可太快了)。但又想用java写,所以用内部类写了个模板仅供自己参考,如下。

package temp.leetcode.editor.cn;



import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;

class Person{
    int id;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getOp() {
        return op;
    }

    public void setOp(int op) {
        this.op = op;
    }

    public int getEd() {
        return ed;
    }

    public void setEd(int ed) {
        this.ed = ed;
    }

    public int getChair() {
        return chair;
    }

    public void setChair(int chair) {
        this.chair = chair;
    }

    int op;
    int ed;
    int chair;
}
class Solution {
    public static int smallestChair(int[][] times, int targetFriend) {
        int[] chair = new int[times.length];//椅子状态
        Person[] p = new Person[times.length];

        for (int i = 0; i < times.length; i++) {
            p[i]=new Person();
            p[i].setId(i);
            p[i].setOp(times[i][0]);
            p[i].setEd( times[i][1]);

        }
        Arrays.sort(p, new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                return o1.getOp() - o2.getOp();
            }
        });

       return 1;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值