File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 105
105
722|[ Remove Comments] ( ./0722-remove-comments.js ) |Medium|
106
106
739|[ Daily Temperatures] ( ./0739-daily-temperatures.js ) |Medium|
107
107
791|[ Custom Sort String] ( ./0791-custom-sort-string.js ) |Medium|
108
+ 796|[ Rotate String] ( ./0796-rotate-string.js ) |Easy|
108
109
804|[ Unique Morse Code Words] ( ./0804-unique-morse-code-words.js ) |Easy|
109
110
819|[ Most Common Word] ( ./0819-most-common-word.js ) |Easy|
110
111
821|[ Shortest Distance to a Character] ( ./0821-shortest-distance-to-a-character.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 796. Rotate String
3
+ * https://leetcode.com/problems/rotate-string/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given two strings s and goal, return true if and only if s can become goal
7
+ * after some number of shifts on s.
8
+ *
9
+ * A shift on s consists of moving the leftmost character of s to the rightmost
10
+ * position.
11
+ *
12
+ * For example, if s = "abcde", then it will be "bcdea" after one shift.
13
+ */
14
+
15
+ /**
16
+ * @param {string } s
17
+ * @param {string } goal
18
+ * @return {boolean }
19
+ */
20
+ var rotateString = function ( s , goal ) {
21
+ for ( let i = 0 ; i < s . length ; i ++ ) {
22
+ if ( s . slice ( i ) + s . slice ( 0 , i ) === goal ) return true ;
23
+ }
24
+ return false ;
25
+ } ;
You can’t perform that action at this time.
0 commit comments