Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit03733eb

Browse files
authored
Merge pull request#109 from bishalp22/patch-5
Create Detect Capital
2 parents32fa732 +a20f9ce commit03733eb

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

‎Detect Capital‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Detect Capital
2+
Level-Easy
3+
4+
We define the usage of capitals in a word to be right when one of the following cases holds:
5+
All letters in this word are capitals, like "USA".
6+
All letters in this word are not capitals, like "leetcode".
7+
Only the first letter in this word is capital, like "Google".
8+
Given a string word, return true if the usage of capitals in it is right.
9+
Example 1:
10+
Input: word = "USA"
11+
Output: true
12+
Example 2:
13+
Input: word = "FlaG"
14+
Output: false
15+
Constraints:
16+
1 <= word.length <= 100
17+
word consists of lowercase and uppercase English letters.
18+
19+
Time Complexity-o(n)
20+
Space Complexity-o(1)
21+
22+
Java Solution
23+
24+
class Solution {
25+
public boolean detectCapitalUse(String word) {
26+
if(word.length()>=2 && word.charAt(0)>=97 && word.charAt(0)<=123 && word.charAt(1)>=65 && word.charAt(1)<=91)
27+
return false;
28+
for(int i=1;i<word.length()-1;i++){
29+
if(word.charAt(i)>=65 && word.charAt(i)<=91){
30+
if(word.charAt(i+1)>=65 && word.charAt(i+1)<=91);
31+
else
32+
return false;
33+
}
34+
else{
35+
if(word.charAt(i+1)>=97 && word.charAt(i+1)<=123);
36+
else
37+
return false;
38+
}
39+
}
40+
return true;
41+
}
42+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp