LeetCode: Check If String Is a Prefix of Array Solution
Accumulated concatenation and checkApproach
On each concatenation of words
, compare with s
Implementation
1var isPrefixString = function (s, words) {2 let res = false34 words.reduce((acc, word) => {5 acc += word6 if (acc === s) res = true7 return acc8 }, "")910 return res11}
Comments
Loading comments...
Tags
leetcode
array
string
Apply and earn a $2,500 bonus once you're hired on your first job!
Clients from the Fortune 500 to Silicon Valley startups
Choose your own rate, get paid on time
From hourly, part-time, to full-time positions
Flexible remote working environment
A lot of open JavaScript jobs!!
Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.
Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.
Next Post
LeetCode: Concatenation of Array
.concat() or spread operator
Previous Post
LeetCode: Remove Duplicates from Sorted List
Keep jump over next node until values are not equal