剑指 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) {
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. 删除链表的节点
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;
}
}