剑指 Offer 42. 连续子数组的最大和 剑指 Offer 48. 最长不含重复字符的子字符串 剑指 Offer 18. 删除链表的节点

剑指 Offer 42. 连续子数组的最大和

class Solution {
    public int maxSubArray(int[] nums) {
        if(nums.length<1) return 0;
        int res=nums[0];
        int max=nums[0];
        for(int i=1;i<nums.length;i++){
            res=Math.max(res+nums[i],nums[i]);
            max=Math.max(res,max);
        }
    return max;
    }
}

剑指 Offer 48. 最长不含重复字符的子字符串

class Solution {
    public int lengthOfLongestSubstring(String s) {
             //错误原因:1.误以为所有字符都是小写的
                      //2.误以为所有字符都是大小写字母
            if(s.length()==0) return 0;
           int res=1;
           for(int i=0;i<s.length();i++){
        int temp=0;
        HashMap<Character,Integer> map=new HashMap<>();
        for(int j=i;j<s.length();j++){
        char c=s.charAt(j);
        if(map.containsKey(c)){ 
            break;
        }
        map.put(c,map.getOrDefault(c,0)+1);
        temp++;
        res=Math.max(res,temp);
        }
           }
    return res;
    }
}

剑指 Offer 18. 删除链表的节点

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public ListNode deleteNode(ListNode head, int val) {
        if(head==null) return head;
        if(head.val==val) return head.next;
        ListNode cur=head;
         ListNode temp=head;
        while(cur.next!=null){
            temp=cur;
            cur=cur.next;
            if(cur.val==val){
                temp.next=cur.next;
            } 
        }
        if(cur.val==val) temp.next=null;
        return head;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值