File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,161 LeetCode solutions in JavaScript
1
+ # 1,162 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
909
909
1160|[ Find Words That Can Be Formed by Characters] ( ./solutions/1160-find-words-that-can-be-formed-by-characters.js ) |Easy|
910
910
1161|[ Maximum Level Sum of a Binary Tree] ( ./solutions/1161-maximum-level-sum-of-a-binary-tree.js ) |Medium|
911
911
1162|[ As Far from Land as Possible] ( ./solutions/1162-as-far-from-land-as-possible.js ) |Medium|
912
+ 1163|[ Last Substring in Lexicographical Order] ( ./solutions/1163-last-substring-in-lexicographical-order.js ) |Hard|
912
913
1189|[ Maximum Number of Balloons] ( ./solutions/1189-maximum-number-of-balloons.js ) |Easy|
913
914
1200|[ Minimum Absolute Difference] ( ./solutions/1200-minimum-absolute-difference.js ) |Easy|
914
915
1206|[ Design Skiplist] ( ./solutions/1206-design-skiplist.js ) |Hard|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1163. Last Substring in Lexicographical Order
3
+ * https://leetcode.com/problems/last-substring-in-lexicographical-order/
4
+ * Difficulty: Hard
5
+ *
6
+ * Given a string s, return the last substring of s in lexicographical order.
7
+ */
8
+
9
+ /**
10
+ * @param {string } s
11
+ * @return {string }
12
+ */
13
+ var lastSubstring = function ( s ) {
14
+ let i = 0 ;
15
+ let j = 1 ;
16
+ let k = 0 ;
17
+ const n = s . length ;
18
+
19
+ while ( j + k < n ) {
20
+ if ( s [ i + k ] === s [ j + k ] ) {
21
+ k ++ ;
22
+ } else if ( s [ i + k ] < s [ j + k ] ) {
23
+ i = Math . max ( i + k + 1 , j ) ;
24
+ j = i + 1 ;
25
+ k = 0 ;
26
+ } else {
27
+ j += k + 1 ;
28
+ k = 0 ;
29
+ }
30
+ }
31
+
32
+ return s . substring ( i ) ;
33
+ } ;
You can’t perform that action at this time.
0 commit comments