File tree 3 files changed +45
-2
lines changed
3 files changed +45
-2
lines changed Original file line number Diff line number Diff line change 36
36
| [ 021] [ 021-question ] | [ Merge Two Sorted Lists] [ 021-tips ] | [ ✅] [ 021-java ] | [ ✅] [ 021-js ] | [ ✅] [ 021-kotlin ] |
37
37
| [ 026] [ 026-question ] | [ Remove Duplicates from Sorted Array] [ 026-tips ] | [ ✅] [ 026-java ] | [ ✅] [ 026-js ] | [ ✅] [ 026-kotlin ] |
38
38
| [ 027] [ 027-question ] | [ Remove Element] [ 027-tips ] | [ ✅] [ 027-java ] | [ ✅] [ 027-js ] | [ ✅] [ 027-kotlin ] |
39
- | [ 028] [ 028-question ] | [ Implement strStr()] [ 028-tips ] | [ ✅] [ 028-java ] | | [ ✅] [ 028-kotlin ] |
39
+ | [ 028] [ 028-question ] | [ Implement strStr()] [ 028-tips ] | [ ✅] [ 028-java ] | [ ✅ ] [ 027-js ] | [ ✅] [ 028-kotlin ] |
40
40
| [ 035] [ 035-question ] | [ Search Insert Position] [ 035-tips ] | [ ✅] [ 035-java ] | | [ ✅] [ 035-kotlin ] |
41
41
| [ 038] [ 038-question ] | [ Count and Say] [ 038-tips ] | [ ✅] [ 038-java ] | | [ ✅] [ 038-kotlin ] |
42
42
| [ 053] [ 053-question ] | [ Maximum Subarray] [ 053-tips ] | [ ✅] [ 053-java ] | | [ ✅] [ 053-kotlin ] |
358
358
[ 021-js ] : ./src/_021/Solution.js
359
359
[ 026-js ] : ./src/_026/Solution.js
360
360
[ 027-js ] : ./src/_027/Solution.js
361
+ [ 028-js ] : ./src/_028/Solution.js
361
362
[ 226-js ] : ./src/_226/Solution.js
362
363
[ 561-js ] : ./src/_561/Solution.js
363
364
[ 643-js ] : ./src/_643/Solution.js
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {string } haystack
3
+ * @param {string } needle
4
+ * @return {number }
5
+ */
6
+ var strStr = function ( haystack , needle ) {
7
+ if ( haystack && needle ) {
8
+ var x = haystack . split ( needle )
9
+ if ( x . length > 1 ) {
10
+ return x [ 0 ] . length
11
+ } else {
12
+ return - 1
13
+ }
14
+ } else if ( haystack === '' && needle !== '' ) {
15
+ return - 1
16
+ } else {
17
+ return 0
18
+ }
19
+
20
+ } ;
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ kotlin(200ms/87.50%):
46
46
``` kotlin
47
47
class Solution {
48
48
fun strStr (haystack : String , needle : String ): Int {
49
-
49
+
50
50
if (haystack.isEmpty()) {
51
51
return if (needle.isEmpty()) haystack.length else - 1
52
52
}
@@ -85,7 +85,29 @@ class Solution {
85
85
}
86
86
}
87
87
```
88
+ javascript:
89
+ ``` javascript
90
+ /**
91
+ * @param {string} haystack
92
+ * @param {string} needle
93
+ * @return {number}
94
+ */
95
+ var strStr = function (haystack , needle ) {
96
+ if (haystack && needle) {
97
+ var x = haystack .split (needle)
98
+ if (x .length > 1 ) {
99
+ return x[0 ].length
100
+ } else {
101
+ return - 1
102
+ }
103
+ } else if (haystack === ' ' && needle !== ' ' ){
104
+ return - 1
105
+ } else {
106
+ return 0
107
+ }
88
108
109
+ };
110
+ ```
89
111
90
112
## 结语
91
113
You can’t perform that action at this time.
0 commit comments