본문 바로가기
나는 이렇게 학습한다/Algorithm & SQL

1201. Is the string uppercase?

by daco2020 2022. 12. 1.

Is the string uppercase?

Task

Create a method to see whether the string is ALL CAPS.

Examples (input -> output)

"c" -> False
"C" -> True
"hello I AM DONALD" -> False
"HELLO I AM DONALD" -> True
"ACSKLDFJSgSKLDFJSKLDFJ" -> False
"ACSKLDFJSGSKLDFJSKLDFJ" -> True

In this Kata, a string is said to be in ALL CAPS whenever it does not contain any lowercase letter so any string containing no letters at all is trivially considered to be in ALL CAPS.



Solution:

bool isUpperCase(String str) {
  for (String s in str.split('')) {
    if (s.toUpperCase() != s) {
      return false;
    }
  }
  return true;
}
bool isUpperCase(String str) => str.toUpperCase() == str;


'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

1203. String repeat  (0) 2022.12.04
1202. Count by X  (0) 2022.12.02
1130. Square(n) Sum  (0) 2022.11.30
1129. Bin to Decimal  (0) 2022.11.29
1128. Hex to Decimal  (0) 2022.11.28