-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathransomNote.html
More file actions
61 lines (54 loc) · 1.43 KB
/
ransomNote.html
File metadata and controls
61 lines (54 loc) · 1.43 KB
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
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ransom Note</title>
</head>
<body>
<h1>
Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters
from magazine and false otherwise.
</br>
Each letter in magazine can only be used once in ransomNote.
</h1>
<h2>
Example 1:
Input: ransomNote = "a", magazine = "b"
Output: false
</br>
Example 2:
Input: ransomNote = "aa", magazine = "ab"
Output: false
</br>
Example 3:
Input: ransomNote = "aa", magazine = "aab"
Output: true
</h2>
</body>
<script>
var ransomNote = "aabaaaasa"
var magazine = "baasaaaaaba"
var notearray = Array.from(ransomNote)
var magarray = Array.from(magazine)
// var i = 0
// var j = 0
for (var i = 0; i < notearray.length; i++) {
for (var j = 0; j < magarray.length; j++) {
if (notearray[i] == magarray[j]) {
notearray.splice(i, 1)
magarray.splice(j, 1)
i--
j--
}
}
}
if (notearray.length == 0) {
console.log("True");
}
else {
console.log("False");
}
</script>
</html>