在Leetcode写反转链表时遇到了我看不懂的报错
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* reverseList(struct ListNode* head){
if(head==NULL)
return head;
struct ListNode* cout[1000];
int i=0;
struct ListNode* p=head;
struct ListNode* wei=NULL;
while(p->next!=NULL)
{
cout[i++]=p;
p=p->next;
}
wei=p;
while(i>=0)
{
i--;
p->next=cout[i];
p=p->next;
}
return wei;
当i等于0时,你先i--,那么i就等于-1了啊,这样cout[i]就出现下标为-1的错误了。改成while(i>0)
建议优先按题目tag刷题
边做边根据题目总结算法模板和套路
前300道,尽量能刷两遍
,大部分题目代码量控制在50行以内,能够bug free且快速地写出常用的代码块(比如union find, dfs/bfs几个变种, binary search, partition等等)
尽量选用更简单的数据结构,缩短运行时间,化繁为简。能用vector坚决不用unordered_map
一天一道题很难坚持下来,也很难总结。建议一定要集中时间刷。
尽早每周参与LeetCode contest
,保持手感
洛谷练习场做了专题,DP,图论,线段树,买了几本算法竞赛的书,看了些基础内容。oi或者acm的高级算法解面试题有点想多了,一般普通思路即可。
《算法导论》
为什么推荐做LeetCode周赛?
刷LeetCode就能顺利应付面试了吗?还需要做什么?