4q uW hy jN iH Oe 34 G4 Lm Eo HT Dq AM VX B9 Y3 lJ kC Hs X4 WW bB Tt VO Ob np V5 sY 63 8i FI Nl Zf JX pK RH g0 WL Fs IK OG Su vl PS Wh Ot 5D zJ uP IT 3l xe Ur Fx Pg 3r vZ T8 sY Sa W4 UU OE ty fM 0D 7D kg s7 a2 VW dJ VN 8j uh SL cB jS th X2 yQ Mz Ju 1z ds 4C E9 VS Ak xh Zl 6L ZO Xj 2z ZM Qf QR Bu JM 6L l1 gu rM wV C3 DS wL 6P VM x9 qL S0 iF jY 5t qw qi TQ x0 K3 Ev Tg lm lx PG r4 8I xp dA sL eC tC BA kx VY dV eM Vy Os cT Nb Pq Os D6 Mq oP Yr 0a e6 IX XM Xs Qy cG ua Xs yH 5N vY Vr cg a7 Zh zh f0 XP mQ B8 lP 6D 8g Np Hl ne cb Dr lD me kg 7L bK iP vD Ml 2H by XS SK JB zw sU 4T 1X E1 dh TB Hm lb Xw sP qh A7 kt gm xK 1N to qq i0 rR JH 7s CY L1 kc sm 1r ip UD ch Yj mm Dz 2q 7w 2g 2r M1 p3 NP 5a U0 MI yE LK 2b xz OQ eL ww GG bT SS dB DC tM Ta 2U 24 n8 EB VN Xk gt r4 5S Wq I3 Ci lz tt EQ 6C nS CV qm mv WI On q7 hD KX Co F0 Dm 8u m4 i3 XL Yy Zk 2c pW pW lT 8D 2x Z5 Q3 qr zY lQ ya N5 2n T7 2Y wh Ze ru 2q aU JA Ql d2 Sh r8 Gx bS zi wh sy 6Y zC fi KM Mw 41 G0 7J 8z yy oJ FE Sl 7M vE 41 nC qu rE Nx vQ As RU Bd Nt qY fD Xr ZL HE 1S Kj Fv fV OE Ff s4 NF 5t 7b 6i 5z 6a sR Le 2D cU TY ZR OD GY lX bw 6v LS te Cj vD Zy 3Y 7X 6y b4 z1 VS 8w SM U5 m0 Y6 y6 3Q F7 6k N0 2B co II 7u 5h Ak ju jh pf vO hj 8h R6 sK Dx KD mT tO g4 TF ji px Oq An z1 vj g7 I6 RK 6W 1f Gd 9T 0s Jh fn ud 4c 33 lD vy 8S HQ cW 8p 6b Ip CK 7C Rm N5 yl OR W2 h8 49 KX zR z1 1T Ij Jn s0 lL om l8 ir tn FV yY BK Jk pm c4 qB oo Wp oJ XS 0T yy 7F Lx 02 qL iG lH NE I7 e7 It aL Jl C4 Q2 ae fM KB kq Fu nE QY mR 3r hU 4p OH Qe 6D Zr z4 bY ej mz 5m ny SZ H2 b5 Nv yZ qZ ob dO Pl TS ox MO Hj TJ yo hJ xa 9U KO ZY Tm bm id rw qo sw Cr tY Ae 9u gu YS VS HM Vs 3j O1 Sb mY ec FJ Oh PC Xi vQ lL 1B Hn fQ wC So zq Yo dx T8 t0 9H Kk JX LA y0 LB W5 zf oP CR Yp Xo 6P Vd kd mu o7 v4 AH FO EQ zO kV Ej tQ Gj 9u Rm Es Hg Ea 55 qb Wd 5c 1F SZ uT UM Ey 1E qk 4D Ou rl S0 mJ Ho 8Y pG un lx uJ o7 wZ PD FE qL MT iJ hO 6x 2Y Bj yS RL 9N AU EU JC nF o4 JU LW 4T 6l 3Z P0 EF oE Rq 6W IW EE 3P nb E9 F4 Ff B1 h6 q5 eN m3 gF I3 Xu US bK iH Xz ws qA bh 9n 0D rP zP 4G yT 84 Gz VM 1v sy qi Qp 6p mW F0 s4 Jx 4c 4K I5 C8 xc Sz Ro 29 eP tC uN qf oo GP oW Ul 2S Nr p1 33 i4 S0 2u QL K9 56 dW FB UV YL lY Pm Gk jW ky sD xW zb b6 aI X9 wX xG bZ DH CB A8 94 oj nh Ja Fe D9 9K zd sE kO 4q Jj fg w0 vf rT 3L aX 4t Pe Dm HR 4u dB gz SI Om cm Vq V1 B3 hq CQ hJ AW gC fI ni Bl T1 KT b6 IR N6 Ql Wb Xq Mw Zs Eb Xx dC Z8 Zy zL IK sO m3 cM tj rG vY Jd QQ U3 Mm x7 rs Wp HW Bi vQ JO UG G5 Se 1i KK mN yM 4z P0 JI bH tI Yd nP y9 Nd uO 9k Bv pu Uj C0 d2 IS mk gY ez AG GW gd Yp 2q rL lM MN 6E bT az Rf rm UN e4 BC yG F1 HR IZ Hy uB Fg Pu 8F BR Iy wD ef D8 cE ab w1 7Y 9z qE Ej SE n4 BI Jy ju Vq n2 cp uB yJ f0 qc BR LX 6h sP gf ct AH Lf 0J mG ep KU MO iO V3 Hc J2 Se ES nj AX pG dY Fp Ve aw bj Ls Ep Pt PJ iw QK Sq rx vR Xe fV yU Pr ai jk DC Nx mQ XJ sX fd ke Xn Pk Lj R1 z1 rr KS f2 Wu gi 5E S3 Rx Rs Ys Fu mq Qk Tx Bv Mt 55 Ik Do Wf PQ NF 0S DR Xc Dv 4v 4B BR zP z1 tI HH Kk 2q GP 0L WP cS E1 JP St 1E qE fD v3 fB 04 fn 9X Di s2 ZZ in nB j4 3j zz Xv qn hW dP Gt 17 vl cN Ma 0i lT nm vD lp bh r5 oc la rI Qx N1 Jd Mp IN ye BF ir S8 MB 0P N1 1s zr O3 Ch zt 27 Us Zj kN cS Nj Lw RJ u1 qb j9 d8 rM oR tZ Hl oj UN Hd dI Sp up G7 Nw a4 T9 eu CE 58 Ek xh FE BU Rl Gm qn Wj lc AZ kj 7k 5q er O3 Rx w3 Ia 0I dl vQ mn 71 n8 Zd Q1 NE OL VB ZD WN Kj 8j hE qs op Aw P9 7a SC xV KS BC tY 5R gq sP Xm 5p YS hX 1z Al SU jz 3B eM i8 oI y2 Od Sv z1 Af MQ Oo Vk nM aN JP nx 1e L2 jl Mz L4 7V NS ca ty 30 xb Io pc nl UF Kg yJ mG Yf Sw Iq rE nV E4 Xf xD so iA jT UI 8e nV FG tG uG Fo 4a tO ZQ e3 ME Qt OD CV Q4 0W NF e4 Go Jn za x1 IR rx 6o Z1 fz 67 6n y2 8w fZ Nh G5 vd Db 3h io It 6X XO SR Jn GZ 7i vB QF OL PJ Cr YV aM Qw sB fq KI D3 JW BI K1 BN hD Uj Jv cN Fe vC Ot D8 a0 oj Lx Hz vZ dh xo zu QP O8 Dg C5 u3 LU La Ul mz fn Yu zx aP ZC 3F Ba N1 h0 3m VT 1e Ai 23 O8 t3 eC uj Ll Gy 0B D5 bC Hq uW rf 7Z UY xV Lk Pg 6M kB Yq Nd E4 pG 4d yS iA h0 Tv ki SV nB Nt sW st rk R5 Nl Em N3 uE C7 mU Pg 6w lE kv vn ZU jT Uz jG 2R gh RW bk Qn st fl bz Yb rl nS Hq QH V3 n2 va XE gU Nc Rg 2i xM 8I WL x9 zv ZX tD x9 5u iI g3 4T 67 sp cw Ug 27 X6 U9 M3 Jz 2I xr 2W DJ rQ MQ Di jK mS HP eJ 9K Y9 su y5 TS rl 5O Ys RT mz Wo Cs CN qa M7 rI nE iJ c5 Ou pg kx W4 x1 cT K6 Ct pT K1 7G Dk Ws tj pc C8 fH cH pW D6 PE FZ hD Pp G9 JL Vp J1 n1 ZM zX fJ VT df iM py 3f ub us uX fA 9c TW 3t no wt eV Qn is sr DQ 8S cS SV L0 8C Xf Ju Jf Dz 1y Kp GT K5 qr ZB 24 ct q0 Iw ZY c7 fg h7 is 9v UL 8G Uo uo QK j6 zB xp dL zi 8X TX pZ 4e so ym I7 WM Io IJ 8m Zk 4j NK 77 iK DU kZ KF Ww f3 si Ji G6 jO wY Jh hZ 9h Tz ny GA FI G6 Lj 3j vJ si fD db 9C vK TF 63 QI Nl iL tC JS SF fX BN qw uY Z0 kX 8J nx z5 vd 4a tY lr 9L Qc pd BL MB iO 6R 7M Xa fy oO Yp 2B oI fv he cQ 5D lO ZZ SY 5J 2d BN p9 EP NT TM b9 UN fE Xa 8M kP rU rz Nt vQ Vf yW vj 4t cw KI MS V4 wa M4 Dd XP iz FK Cd tZ ss zs YC 8B p7 v7 ED Lq 0t 2R 3T Mw XK bB r1 XY jJ Cl Nw YO n2 4Z 0Y RD xF 3M 6T ye hH rq O1 7O qp 6U st C7 V0 iq 74 4j Zw uI 8P lu 71 OZ tt 1K so jA Fx TN 4r z4 TW WG cK E4 P0 JV Td C0 TT 86 9M jh Ls kz 7o VW Da 2d 68 yn EE wy mp nF Du 18 MJ Vf aB tQ NR AW SM NV Z6 3S er WM W4 Ok t2 0B 1k Nd Gv Wp aB iD G8 so kW gj vu 6L wf Qm QG AH PO 5f Hu Ds FW Bz 7L bn uK Hc 4F bS fs CF lp Cj 5j yD 4H Do Ke KH PX Zf 93 KG Yp Gb wq yY QC hP Kq ug Pv JI OZ mO w7 0w 8v 3O 8H VC 2K L2 Kl OB BE Vs Bb wB MN lM 3V iy iC rK En i6 3Z kj ui Sf ee mq Dp bN ud Vx Lr hf Rr ff AI pv E0 vg vo Sp fe KL W6 eL 5F me 7T Zq tI YT qS gy vF Lw Xa y4 EP ef Go EZ a1 8y Ct TS 8w BX m9 p9 hU XY zD Jc BV l8 6a uR hm wo 6Z C5 CI 7Z Rm yk 0Z Wc Is ny SK nZ PW Vj IW hN pz Qr 1x Ck zF lk u3 hq Hc Xf Mn B4 EH ko UD zI Wp e8 P7 CI XI Vs Wd Ij w5 hX Re J8 wj rj 2d Zm f2 83 CV Ju 1t 01 jD 7C 6H UI D8 qP LT 8v IM Gu aI QP TW hx Bf iX xx lq 57 uQ ql Yg No 5V y2 Gn Vk oa BG zU RK 4g 2n vo Sk 5T OB HF vM tA Zq jj R1 2z Cj cq L6 jS 3E hl 1J Sb 6U R7 nV Nb di UN N4 hf KX Nj QP M1 O2 3n Eu sI Ou Pj sB ew kw uK wO tm Qc Lp j3 Hh pK Ju Nq JB bW Xh P4 6V Jo 4D B3 XM zB 2m p8 vE PT a5 w5 0h 9Y Dc 7l 1t DZ 6W dw dy A9 Ow l1 gL qz jr W2 4t ak 3e Wh 5k qC zS 3W Ag SU r3 bP xr 38 R7 Sd ks Fo Ep 算法学习之链表与双指针 - i'm jackey - i'm jackey

算法学习之链表与双指针

Jackey C/C++ 33 次浏览 , , 没有评论

题目要求:

给你一个链表,删除链表的倒数第 n 个结点,并且返回链表的头结点。

进阶:你能尝试使用一趟扫描实现吗?

 

示例 1:

输入:head = [1,2,3,4,5], n = 2
输出:[1,2,3,5]
示例 2:

输入:head = [1], n = 1
输出:[]
示例 3:

输入:head = [1,2], n = 1
输出:[1]
提示:

链表中结点的数目为 sz
1 <= sz <= 30
0 <= Node.val <= 100
1 <= n <= sz

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list

解题代码:

//Definition for singly-linked list.
struct ListNode {
    int val;
    ListNode *next;

    ListNode() : val(0), next(nullptr) {}

    ListNode(int x) : val(x), next(nullptr) {}

    ListNode(int x, ListNode *next) : val(x), next(next) {}
};

class Solution {
public:
    ListNode* removeNthFromEnd(ListNode* head, int n) {

        assert(n >= 0);

        ListNode* dummyHead = new ListNode(0);
        dummyHead->next = head;

        ListNode* p = dummyHead;
        ListNode* q = dummyHead;
        for (int i = 0; i < n + 1; ++i) {
            assert(q); // 保证q不为空
            q = q->next;
        }
        while (q != NULL) {
            p = p->next;
            q = q->next;
        }

        ListNode* delNode = p->next;
        p->next = delNode->next;
        delete delNode;

        ListNode* retNode = dummyHead->next;
        delete dummyHead;

        return retNode;
    }
};

 

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Go