Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- java
- Counting
- 자바
- 파이썬
- string
- array
- bit manipulation
- Stack
- 코테
- greedy
- two pointers
- implement
- dynamic programming
- Data Structure
- Matrix
- Binary Tree
- SQL
- geometry
- 코딩테스트
- Tree
- Binary Search
- Math
- Number Theory
- simulation
- sorting
- Method
- database
- 구현
- hash table
- Class
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 2496. Maximum Value of a String in an Array 본문
1. Input
1) String[] strs
2. Output
1) strs의 각 요소에 대해 다음과 같은 값을 계산했을 때 가장 큰 값을 반환
- 문자열이 숫자로만 이루어져 있다면 해당 문자열의 10진수가 문자열의 값이 된다.
- 그 외의 문자열은 문자열의 길이가 값이 된다.
3. Constraint
1) 1 <= strs.length <= 100
2) 1 <= strs[i].length <= 9
3) strs의 요소는 영어 소문자와 숫자들로 이루어져 있다.
4. Example
Input: strs = ["alic3","bob","3","4","00000"] -> Output: 5
설명:
- "alic3": 섞임 -> 길이 = 5
- "bob": 문자만 -> 길이 = 3
- "3": 숫자 -> 3
- "4“: 숫자 -> 4
- "00000": 숫자 -> 0
- 따라서 가장 큰 5를 반환한다.
5. Code
1) 첫 코드(2023/05/05)
class Solution {
public int maximumValue(String[] strs) {
int max = 0;
for(int i=0 ; i<strs.length ; i++){
if(strs[i].matches("[0-9]+"))
max = Math.max(max, Integer.valueOf(strs[i]));
else
max = Math.max(max, strs[i].length());
}
return max;
}
}
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 2506. Count Pairs Of Similar Strings (0) | 2023.05.06 |
---|---|
[LeetCode/Easy] 2500. Delete Greatest Value in Each Row (0) | 2023.05.05 |
[LeetCode/Easy] 2490. Circular Sentence (0) | 2023.05.05 |
[프로그래머스/Lv.0] 옹알이 (1) (0) | 2023.05.04 |
[프로그래머스/Lv.0] 그림 확대 (0) | 2023.05.04 |