0
点赞
收藏
分享

微信扫一扫

AC算法每日打卡-删除链表的节点-正则表达式匹配

外贸达人小峻先森 2022-04-07 阅读 54
leetcode

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

class Solution {
public:
ListNode* deleteNode(ListNode* head, int val) {
ListNode* new_head = new ListNode(0);
new_head->next = head;
ListNode* cur = head;
ListNode* ptr = new_head;
while (cur != NULL && cur->val != val) {
ptr = cur;
cur = cur->next;
}
ptr->next = cur->next;
return new_head->next;
}
};

剑指 Offer 19. 正则表达式匹配

class Solution {
public:
bool isMatch(string s, string p) {
if(p.empty()) return s.empty();
bool match=!s.empty()=p[0] || p[0]=='.');
if(p.length()>=2 ='*'){

return isMatch(s,p.substr(2)) || match && isMatch(s.substr(1),p);
}else{
if(match)
return isMatch(s.substr(1),p.substr(1));
else
return false;
}
}
};
举报

相关推荐

0 条评论