2021.11.11

File类的作用

image-20211111135224571

能够读写文件的是数据流(OutputStream和InputStream)

内部类

image-20211111135319148

​ 静态内部类:

可以访问外部类的静态成员变量,包括私有变量,但是不能访问非晶态资源,可以不依赖外部类实例而实例化

​ 成员内部类:

可以访问外部所有成员变量,但是自己不能定义静态资源,因为其实例化本身就依赖这外部类

​ 局部内部类:

局部内部类,就像是一个内部方法,不能被访问修饰符修饰,也不能被static修饰,

只能访问所在代码块或者方法被定为为final的局部变量

​ 匿名内部类:

没有类名的内部类,不能使用class,extends和implements,没有构造方法

不能定义静态资源,

匿名内部类是局部内部类的特殊形式,所以局部内部类的显示对匿名内部类有效

剑指 Offer 21. 调整数组顺序使奇数位于偶数前面 - 力扣(LeetCode) (leetcode-cn.com)

class Solution {
    public int[] exchange(int[] nums) {
        int i = 0,j=nums.length-1;
        int temp;
        while(i<j){
            while(i<j && nums[i]%2==1){
                i++;
            }
            while(i<j && nums[j]%2==0){
                j--;
            }
            temp = nums[i];
            nums[i] = nums[j];
            nums[j] = temp;
        }
        return nums;
    }
}

剑指 Offer 22. 链表中倒数第k个节点 - 力扣(LeetCode) (leetcode-cn.com)

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public ListNode getKthFromEnd(ListNode head, int k) {
        //快慢指针
        ListNode slow = head,fast = head,per = null;
        int i =0;
        while(fast!=null){
            if(i==k){
                break;
            }   
            fast = fast.next;
            i++;
        }
        while(fast!=null){
            fast = fast.next;
            slow = slow.next;
        }
return slow;
        //方向看错了,不过就当复习反转链表了
        // //反转链表
        // //从slow开始到null;
        // fast = slow;
        // while(fast!=null){
        //     fast = fast.next;
        //     slow.next = per;
        //     per = slow;
        //     slow = fast;
        // }
        // return per;
    }
}

剑指 Offer 24. 反转链表 - 力扣(LeetCode) (leetcode-cn.com)

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

//哈哈哈,巧了,刚用上
class Solution {
    public ListNode reverseList(ListNode head) {
        ListNode pre = null,cur = head;
        while(head!=null){
            cur = head.next;
            head.next = pre;
            pre = head;
            head = cur;
        }
        return pre;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值