코딩하는 털보

11 to 9, Day 15 본문

Diary/Eleven to Nine

11 to 9, Day 15

이정인 2021. 3. 19. 20:29

Today, ToDoList

  • 이력서 만들기
  • 코딩 문제 풀기

나의 새로운 이력서 페이지...

https://www.notion.so/Let-the-work-begin-d36ddab688774e179e80ea6959d5fca6

정원희 님의 블로그에 있는 이력서 작성법 포스팅을 참고해서 작성하였다.

https://wonny.space/writing/work/engineer-resume


  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.

int 배열에서 합이 특정 값이 되는 두 값의 index 배열 반환

Example 1:

Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Output: Because nums[0] + nums[1] == 9, we return [0, 1].

Example 2:

Input: nums = [3,2,4], target = 6
Output: [1,2]

Example 3:

Input: nums = [3,3], target = 6
Output: [0,1]
class Solution {
    public static int[] twoSum(int[] nums, int target) {
        int num1;
        int num2;
        int[] result = new int[2];
        for (int i = 0; i < nums.length; i++) {
            num1 = nums[i];
            for (int j=i+1; j < nums.length; j++) {
                num2 = nums[j];
                if ( num1 + num2 == target ) {
                    result[0] = i;
                    result[1] = j;
                    return result;
                }
            }
        }
        return null;
    }
}
Comments