-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstrings.js
More file actions
51 lines (30 loc) · 891 Bytes
/
Copy pathstrings.js
File metadata and controls
51 lines (30 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// function reverseString(str){
// let reversed = "";
// for(let i = str.length - 1; i>=0; i--){
// reversed +=str[i];
// }
// return reversed;
// }
// function longestUniqueSubstring(str){
// let map = new Map();
// let start=0, maxLength = 0;
// for (let end=0; end < str.length; end++){
// if(map.has(str[end])){
// start=Math.max(start,map.get(str[end])+1);
// }
// map.set(str[end],end)
// maxLength = Math.max(maxLength,end - start + 1)
// }
// return maxLength;
// }
// console.log(longestUniqueSubstring('aaabbsbdhffjksn'));
function nonRepeatingChar(s){
for(let i = 0; i < s.length ; i++){
const char = s[i];
if(s.indexOf(char) === s.lastIndexOf(char) ){
return char
}
}
return null;
}
console.log(nonRepeatingChar('swiss'));