일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- attribute
- 파이썬
- 프로그래머스
- Python Code
- Generator
- iterator
- 운영체제
- Convert Sorted List to Binary Search Tree
- Decorator
- 315. Count of Smaller Numbers After Self
- 715. Range Module
- 밴픽
- 30. Substring with Concatenation of All Words
- shiba
- Class
- Protocol
- data science
- DWG
- Regular Expression
- LeetCode
- 컴퓨터의 구조
- Python
- Substring with Concatenation of All Words
- 109. Convert Sorted List to Binary Search Tree
- 43. Multiply Strings
- t1
- concurrency
- kaggle
- 시바견
- Python Implementation
Archives
- Today
- Total
Scribbling
[Java 101] 1. Two Sum with HashMap as a counter 본문
class Solution {
public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> map = new HashMap<>();
for (int i=0; i<nums.length; i++){
int num = nums[i];
if (map.containsKey(target-num)) {
return new int[]{i, map.get(target-num)};
}
map.put(num, i);
}
return null;
}
}
'Computer Science > Java' 카테고리의 다른 글
[Java 101] 347. Top K Frequent Elements with HashMap as a counter, PriorityQueue, (0) | 2023.02.14 |
---|---|
[Java 101] 49. Group Anagrams with HashMap, StringBuilder (0) | 2023.02.14 |
[Java 101] 242. Valid Anagram with HashMap (0) | 2023.02.14 |
[Java 101] 217. Contains Duplicate with HashSet, Arrays.stream (0) | 2023.02.14 |
[Java 101] LeetCode: 2. Add Two Numbers (0) | 2023.02.14 |