Skip to content

Commit 69fae15

Browse files
committed
Add solution #796
1 parent 5978d27 commit 69fae15

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
722|[Remove Comments](./0722-remove-comments.js)|Medium|
106106
739|[Daily Temperatures](./0739-daily-temperatures.js)|Medium|
107107
791|[Custom Sort String](./0791-custom-sort-string.js)|Medium|
108+
796|[Rotate String](./0796-rotate-string.js)|Easy|
108109
804|[Unique Morse Code Words](./0804-unique-morse-code-words.js)|Easy|
109110
819|[Most Common Word](./0819-most-common-word.js)|Easy|
110111
821|[Shortest Distance to a Character](./0821-shortest-distance-to-a-character.js)|Easy|

solutions/0796-rotate-string.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
};

0 commit comments

Comments
 (0)