Longest common prefix · พรีฟิกที่ยาวที่สุดร่วมกัน
Longest common prefix
Return the longest string that starts every word in the array. For flower, flow, flight it's fl; if there's nothing in common, return "". Start with the first word as a guess and shrink it against each next word until it fits them all.
พrefix ที่ยาวที่สุดร่วมกัน
กลับสตริงที่ยาวที่สุดที่ เริ่มต้น ทุกคำในอาร์เรย์ สำหรับ flower, flow, flight คำตอบคือ fl; หากไม่มีอะไรเหมือนกัน ให้คืนค่า "" เริ่มด้วยคำแรกเป็นคำเดาและหดมันลงทีละคำจนกว่าจะเข้ากับทั้งหมด
Complete longestCommonPrefix(String[] strs) returning the longest prefix shared by every string. Return an empty string if there is none or the array is empty. · เติม longestCommonPrefix(String[] strs) กลับค่าพรีฟิกที่ยาวที่สุดที่ทุกสตริงร่วมกัน ถ้าไม่มีหรือ array ว่างให้กลับค่าสตริงว่างเปล่า
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่