A string is said to be complete if it contains all the characters from a to z. Given a string, check if it completes or not.
Example:
Input: s = "qwertyuioplkjhgfdsazxcvbnm"
Output: YES
Approach
C++
#include <bits/stdc++.h>using namespace std;void completeString(string s){int len = s.size();int f[26] = {0};for (int i = 0; i < len; i++)f[s[i] - 'a']++;int flag = 0;for (int i = 0; i < 26; i++){if (f[i] == 0){flag = 1;break;}}if (flag == 0)cout << "YES\n";elsecout << "NO\n";}int main(){string s = "qwertyuioplkjhgfdsazxcvbnm";completeString(s);return 0;}
No comments:
Post a Comment