当前位置:网站首页>Double pointer letter matching
Double pointer letter matching
2022-06-30 14:37:00 【Douglas_ LT】
A daily topic ing, Today is a day easy topic 524. Longest Word in Dictionary through Deleting
class Solution {
public:
static bool cmp(string s1, string s2) {
if (s1.size() == s2.size()) {
return s1 < s2;
}
return s1.size() > s2.size();
}
string findLongestWord(string s, vector<string>& dictionary) {
sort(dictionary.begin(), dictionary.end(), cmp);
for (int i = 0; i < dictionary.size(); i++) {
int j = 0, k = 0;
int len1 = dictionary[i].size(), len2 = s.size();
while (j < len1 && k < len2) {
if (dictionary[i][j] == s[k]) {
if (j == len1 - 1) {
return dictionary[i];
}
j++; k++;
}
else {
k++;
}
}
}
return "";
}
};
边栏推荐
- Experiment 2: stack
- Complete TCP forwarding server (kernel linked list + mutex)
- Computer screenshot how to cut the mouse in
- Meaning of while (~scanf ("%d%d", & A, & B))
- How to use Alibaba Vector Icon
- go time. after
- 从控制层返回到js的json数据带“\”转译符,怎么去掉
- JS array sorting method summary
- Vue returns to the previous page without refreshing the page / Vue caches the page
- @PathVariable
猜你喜欢
PS dynamic drawing
How to realize selective screen recording for EV screen recording
2021-07-14 mybaitsplus
remote: Support for password authentication was removed on August 13, 2021. Please use a personal ac
LIS error: this configuration section cannot be used in this path
Error on datetime when importing SQL file from MySQL
V3 03_ Getting started
I love network security for new recruitment assessment
Thinkphp5 log file contains trick
How does hbuilder display in columns?
随机推荐
从控制层返回到js的json数据带“\”转译符,怎么去掉
Mutex lock, read / write lock, spin lock, pessimistic lock, and optimistic lock
org. json. The jsonobject object is converted to JSON, and JSON adds new elements. The value is obtained according to the JSON key. And list object format string to jsonarray
Lost connection to the flow server (0 retries remaining): |Out of retries, exiting! Error reporting solution (flow)
Laravel8 custom log directory, rename
2021-07-15Caused by: org. quartz. ObjectAlreadyExistsException: Unable to store Job : ‘DEFAULT. TASK_ 1‘
【BUUCTF】 Have Fun
Dart extended feature
How to realize selective screen recording for EV screen recording
JMeter transaction controller
Experiment 2: stack
Realize a simple LAN communication (similar to feiqiu)
Cost forecast of PMP (BAC, EAC, etc)
V3 01_ Welcome
V3 03_ Getting started
Introduction to the construction and development of composer private warehouse
Att & CK red team evaluation field (I)
Begin End use the pit encountered
Solution cannot use a scalar value as an array
Wechat applet realizes map navigation + door-to-door recycling