作者:紫色咖啡调 | 来源:互联网 | 2023-09-24 08:47
剑指Offer18.删除链表的节点classSolution{public:ListNode*deleteNode(ListNode*head,intval){ListNode*
剑指 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()&&(s[0]==p[0] || p[0]=='.');if(p.length()>=2 && p[1]=='*'){return isMatch(s,p.substr(2)) || match && isMatch(s.substr(1),p);}else{if(match)return isMatch(s.substr(1),p.substr(1));elsereturn false;}}
};