일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 스프링
- 항해 추천인
- 불친절한SQL프로그래밍
- java
- Python
- 불친절한 SQL 프로그래밍
- 스프링입문
- 자바의정석
- Secure Coding
- 항해 추천인코드
- 제네릭
- 스프링 부트와 JPA
- 이것이자바다
- Numpy
- Spring
- 스프링MVC
- 시큐어코딩
- 스프링 핵심원리
- 자바공부
- 서블릿
- Java의정석
- 항해플러스 회고
- 인프런
- 김영한
- 자바연습문제
- 항해플러스
- JPA
- 자바의정석 연습문제
- 항해플러스 백엔드 7기
- 항해플러스 백엔드
- Today
- Total
Continuous Challenge
[LeetCode] 1. Two Sum _ Map 본문
LeetCode 사이트에서 문제 풀며 코딩 공부하기 1일차
문제 Two Sum - https://leetcode.com/problems/two-sum/
Two Sum - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
나의 풀이 - https://github.com/o3ozzvb/Leetcode/blob/master/src/TwoSum_1.java
GitHub - o3ozzvb/Leetcode
Contribute to o3ozzvb/Leetcode development by creating an account on GitHub.
github.com
나는 이중 포문을 사용하여 문제를 해결하였는데, 좋은 솔루션 중 Map을 활용한 솔루션이 있었다.
Java 문법을 다시 공부하고자 생활코딩 Map 강의를 보며 정의를 재정립하였다.
구름EDU - 모두를 위한 맞춤형 IT교육
구름EDU는 모두를 위한 맞춤형 IT교육 플랫폼입니다. 개인/학교/기업 및 기관 별 최적화된 IT교육 솔루션을 경험해보세요. 기초부터 실무 프로그래밍 교육, 전국 초중고/대학교 온라인 강의, 기업/
edu.goorm.io
Java의 Collection에는 List, Set, Map 이 있다.
그 중에서 Map은 Key-Value의 쌍을 원소로 가지는 Collection Framework 이다.
- Key값은 Value의 값을 가져오는 열쇠의 용도로 사용되며 그렇기 때문에 값의 중복이 불가하다.
- put(key, value) : Map interface에만 존재하는 함수. (Collection interface에는 존재하지 않음)
- Map을 탐색하기 위한 방법
- Iterator 인터페이스의 사용이 불가능한 컬렉션 Map을 탐색하기 위해서는 entrySet() 또는 keySet() 함수를 사용하여 Set 객체를 반환받아 사용한다.
1. entrySet() - Entry는 getKey(), getValue() 함수를 가지고 있다.
static void iteratorUsingForEach(HashMap map){ Set<Map.Entry<String, Integer>> entries = map.entrySet(); for (Map.Entry<String, Integer> entry : entries) { System.out.println(entry.getKey() + " : " + entry.getValue()); } }
2. iterator()
static void iteratorUsingIterator(HashMap map){ Set<Map.Entry<String, Integer>> entries = map.entrySet(); Iterator<Map.Entry<String, Integer>> i = entries.iterator(); while(i.hasNext()){ Map.Entry<String, Integer> entry = i.next(); System.out.println(entry.getKey()+" : "+entry.getValue()); } }
'Study > LeetCode with Java (2021)' 카테고리의 다른 글
[LeetCode] 20. Valid Parentheses _ Stack (0) | 2021.08.08 |
---|