mirror of
https://github.com/Manoj-HV30/dsa-competitive-programming.git
synced 2026-05-16 19:35:22 +00:00
added cses
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
class Solution{
|
||||
public:
|
||||
bool checkOnesSegment(string s){
|
||||
return s.find("01") == string::npos;
|
||||
}
|
||||
};
|
||||
|
||||
//TC: o(n), SC:o(1)
|
||||
|
||||
|
||||
//npos is a special cpp constant stands for "no position" which is essentially not found value, (size_t(-1)) returned by find() and such functions
|
||||
|
||||
/*
|
||||
find()
|
||||
- finds FIRST occurrence of substring
|
||||
|
||||
Example:
|
||||
string s = "banana";
|
||||
s.find("na") -> 2
|
||||
|
||||
--------------------------------
|
||||
|
||||
rfind()
|
||||
- finds LAST occurrence of substring
|
||||
|
||||
Example:
|
||||
string s = "banana";
|
||||
s.rfind("na") -> 4
|
||||
|
||||
--------------------------------
|
||||
|
||||
find_first_of()
|
||||
- finds first character that matches
|
||||
ANY char from a given set
|
||||
|
||||
Example:
|
||||
string s = "hello";
|
||||
s.find_first_of("aeiou") -> 1 // 'e'
|
||||
|
||||
--------------------------------
|
||||
|
||||
find_last_of()
|
||||
- finds last character that matches
|
||||
ANY char from a given set
|
||||
|
||||
Example:
|
||||
string s = "hello";
|
||||
s.find_last_of("aeiou") -> 4 // 'o'
|
||||
|
||||
--------------------------------
|
||||
*/
|
||||
Reference in New Issue
Block a user