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
- todo
- Algorithm
- 써니나타스
- 정보시스템
- todo List
- 미터프리터
- StringBuilder
- 웹해킹
- 모드 설정
- CSRF
- HTML Injection
- stock price
- leetcode
- SQLMap
- metasploit
- 취약점
- meterpreter
- programmers
- study
- 취약점진단
- 모의해킹
- Suninatas
- Router
- ToDoList
- hackerrank
- algotithm
- java
- SQL Injection
- wpscan
- 라우터
Archives
- Today
- Total
보안 / 개발 챌린저가 목표
[AlphaGo Study] [LeetCode] [JAVA] 1. Two Sum 본문
문제 설명
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
You can return the answer in any order.
입출력 예
Input | Output | |
nums | target | |
[2, 7, 11, 15] | 9 | [0, 1] |
[3, 2, 4] | 6 | [1, 2] |
[3, 3] | 6 | [0, 1] |
입출력 예 설명
#예제1
Because nums[0] + nums[1] == 9, we return [0, 1].
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
문제를 풀기 전 THINK
§ nums 안의 두 수를 골라 target의 숫자를 만드는 것.
§ target의 숫자를 만들었을 때의 nums의 index를 반환.
나의 Solution
public class TwoSum {
public static int[] twoSum(int[] nums, int target) {
int[] result = new int[2];
int num_len = nums.length;
for(int i = 0; i < num_len - 1; i++) { // 자기 자신 제외 비교
for(int j = i + 1; j < num_len; j++) { // 앞에 비교한 것 비교X
if(nums[i] + nums[j] == target) {
result[0] = i;
result[1] = j;
break;
} // if end
} // for end
} // for end
return result;
}
}
'Development > Algorithm' 카테고리의 다른 글
[AlphaGo Study] [LeetCode] [JAVA] 43. Multiply Strings (0) | 2020.10.15 |
---|---|
[AlphaGo Study] [LeetCode] [JAVA] 136. Single Number (0) | 2020.10.06 |
[AlphaGo Study] [Programmers] [JAVA] 큰 수 만들기 (0) | 2020.10.03 |
[AlphaGo Study] [LeetCode] [JAVA] 448. Find All Numbers Disappeared in an Array (0) | 2020.09.28 |
[AlphaGo Study] [LeetCode] [JAVA] 21. Merge Two Sorted Lists (0) | 2020.09.24 |
Comments