-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetectCapital.html
More file actions
81 lines (74 loc) · 2.24 KB
/
DetectCapital.html
File metadata and controls
81 lines (74 loc) · 2.24 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!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>LeetCode Day 7</title>
<style>
body {
background: yellowgreen;
}
pre {
font-size: 20px;
color: rgb(17, 0, 255);
}
</style>
</head>
<body>
<h1>
We define the usage of capitals in a word to be right when one of the following cases holds:
</br>
All letters in this word are capitals, like "USA".
</br>
All letters in this word are not capitals, like "leetcode".
</br>
Only the first letter in this word is capital, like "Google".
</br>
Given a string word, return true if the usage of capitals in it is right.
</h1>
<pre>
Example 1:
Input: word = "USA"
Output: true
Example 2:
Input: word = "FlaG"
Output: false
</pre>
</body>
<script>
// there will be mainly three conditions
// if there is only one letter then it must be in capital
// if there are two letter then it can be capital and small
// it should say false if it is more than tree letters and one of them is small and other are false
// var word = ASc here word.length > 2 but captial letters < words.length or
function detectCapitalLetter(word){
var firstletter = word[0]
var length = word.length
var capitalletters = 0
var lowercaseletters = 0
var i = 0
while (i < length) {
if (word[i] == word[i].toUpperCase()) {
capitalletters++
}
if (word[i] == word[i].toLowerCase()) {
lowercaseletters++
}
i++
}
if (firstletter==firstletter.toUpperCase()) {
if (length == lowercaseletters + 1||length == capitalletters) {
return true
}
}
if (capitalletters>0) {
if (length>capitalletters) {
return false
}
}
else return true
}
console.log('detectCapitalLetter(): ', detectCapitalLetter("Bx"));
</script>
</html>