Hướng dẫn how do you find the distance between two words in a string python? - làm thế nào để bạn tìm thấy khoảng cách giữa hai từ trong một chuỗi python?
Cải thiện bài viết Show Lưu bài viết Cho một chuỗi S và hai từ W1 và W2 có trong S. Nhiệm vụ là tìm khoảng cách tối thiểu giữa W1 và W2. Ở đây, khoảng cách là số bước hoặc từ giữa từ thứ nhất và từ thứ hai. & Nbsp;s and two words w1 and w2 that are present in S. The task is to find the minimum distance between w1 and w2. Here, distance is the number of steps or words between the first and the second word. Examples:
Một cách tiếp cận đơn giản là xem xét mọi sự xuất hiện của W1. Đối với mỗi lần xuất hiện của W1, hãy tìm W2 gần nhất và theo dõi khoảng cách tối thiểu. & NBSP;simple approach is to consider every occurrence of w1. For every occurrence of w1, find the closest w2 and keep track of the minimum distance. Implementation: C++
Java
Java
Python3
C#
PHP
JavaScript
Implementation: C++
JavaScript
|