Files
dsa-competitive-programming/leetcode/lc1784.cpp
T
2026-03-11 18:38:08 +05:30

52 lines
932 B
C++

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'
--------------------------------
*/