当前位置:网站首页>刷题《剑指Offer》day07

刷题《剑指Offer》day07

2022-07-31 08:11:00 吃豆人编程

题目来源:力扣《剑指Offer》第二版
完成时间:2022/07/29

17. 打印从1到最大的n位数

image-20220730100416687

我的题解

class Solution {
    
public:
    vector<int> printNumbers(int n) {
    
        vector<int> result;
        for(int i = 1;i < pow(10,n);i++) {
    
            result.push_back(i);
        }
        return result;
    }
};

18. 删除链表的节点

image-20220730100509911

我的题解

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */
class Solution {
    
public:
    ListNode* deleteNode(ListNode* head, int val) {
    
        ListNode* head1 = new ListNode(-1);
        head1->next = head;
        ListNode* tmp = head1;
        while(tmp->next){
    
            if(tmp->next->val == val){
    
                tmp->next = tmp->next->next;
                break;
            }
            tmp = tmp->next;
        }
        return head1->next;
    }
};
原网站

版权声明
本文为[吃豆人编程]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_46369272/article/details/126068449