upd
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
#+title: C++ Tricks
|
||||
|
||||
* Rotate String Check :string:trick:search:
|
||||
:PROPERTIES:
|
||||
:ANKI_NOTE_TYPE: Basic
|
||||
:ANKI_NOTE_ID: 20260504001
|
||||
:END:
|
||||
** Front
|
||||
How to check if string ~s~ can be rotated to match string ~goal~ in O(n)?
|
||||
** Back
|
||||
#+begin_src c++
|
||||
bool rotateString(string s, string goal) {
|
||||
return s.size() == goal.size() && (s + s).find(goal) != string::npos;
|
||||
}
|
||||
#+end_src
|
||||
|
||||
If ~goal~ is a substring of ~s + s~, then ~s~ can be rotated to match ~goal~.
|
||||
Reference in New Issue
Block a user