remember a whilebackwhen I releasedmylastalgorithmvideoandyouaskedformoreandmoreoutgrewbeenvideosand I saidYes, definitely.
I'm goingtocreatemorealgorithmvideosforyou.
Well, asyoucansee, I took a littlewhiletogettothat.
And I'm sorryaboutthat, but I promiseyouthatitisdefinitelyworththewait.
Thisisthebestalgorithmvideo I'vemadesofar.
Andinthisvideo, we'regonnatake a lookatsolving a problemthatactuallyisgreatbecauseitdoesn't testyourknowledgeofremembering a bunchofreallycontrivedalgorithms.
Butitactuallytestyouatthecoreofyourproblemsolvingskillsand a reallyuniqueandchallengingway.
Thiswouldbeexactlythesamehereashavingwhat's called a newlistnodewith a valueofzero.
Andthenwewantedthelistnote.
Next.
Sothislistminute, let's justsetitto a variablehereisgoingtobejustcalledone.
Suchisthefirstelementinourray, andwe'regonnahavetohereisgonnabeequalto a newlistnodeofone, andwewanttodoiswewanttoputonedotnextisgoingtoequalto.
Soessentially, nowwhatwehaveiswehave a linklistwherethefirstelementherehas a valueofzero, andit's got a nextpropertywhichpointstotwo, whichhasthevalueofone.
Sothisisexactlythesameasourrayuphere, butweactuallyaccess E aselementsherebyusingthedotnextproperty, andthat's wherewe'rebeingpassedinhere.
Soweactuallywanttomakesurethatifwehave a numberlargerthan 10 weactuallyneedtorollthatdowntothesmallestnumberhereafterthedecimalpoint.
Andtodothatisalsoreallystraightforward.
Wecanjustcomedownhereafterourcarryoverandwecansaythataresomewhichwe'regonnachangehere, tow a Letwejustwanttosayorsomeisequaltosomemodule 0 10 Andessentially, whatthisdoesisitsaysdividethisnumberoverherebythenumberontherightasmanytimesaspossibleandtellmewhattheremainderis.
Forexample, ifweaddfiveandfive, we'regoingtogethere a sumofzeroafterwedidthemodule.
Oh, butwe'llhave a carryoverofone.
Butweneverusedthatcarryoverafterweexitourloop.
Soweneedtododownhereischeckifwehave a carryoversowecansayifcarryoverisgreaterthanzero.
Soifwehavesomeformofcarryover, weactuallywanttomakesurethatweupendthiscarryovertotheendofourcurrentnoteSowecouldjustcomedownhereandsaycurrent, nodotnextisgoingtobeequalto a newlistnotewithourcarryoverinit.