이끌거나 혹은 따르거나
close
프로필 배경
프로필 로고

이끌거나 혹은 따르거나

  • 분류 전체보기 (91)
    • Java (5)
      • Spring Boot (8)
    • DevOps (17)
      • Git (7)
      • Docker (2)
      • Jenkins (7)
    • Frontend (9)
      • Next.js (4)
      • React (4)
    • 알고리즘 (15)
      • 프로그래머스 (13)
      • LeetCode (2)
    • Dev (22)
      • Database (2)
      • GPT (4)
      • TIP (6)
      • AWS (10)
    • Etc (8)
      • 마시는인생 (3)
      • 구매&사용기 (2)
  • 홈
  • 태그
  • 방명록
[LeetCode] Reverse Integer

[LeetCode] Reverse Integer

(5) Reverse Integer - LeetCode int를 입력받아서 역정렬하여 리턴하라. Example 1: Input: x = 123 Output: 321 Example 2: Input: x = -123 Output: -321 Example 3: Input: x = 120 Output: 21 간단하게 StringBuilder로 역정렬하고 음수인지 양수인지 판단해서 적절하게 바꿔주면 되는문제. 인줄 알았는데 역정렬하고 보니 Int의 범위를 벗어나는 숫자가 나오는 경우가 있다. (1,534,236,469) 따라서 내부 로직은 Long형으로 처리하고 Int의 범위를 벗어나면 0을 리턴하도록 마지막에 처리를 해줘야 한다. class Solution { public int reverse(int x) { ..

  • format_list_bulleted 알고리즘/LeetCode
  • · 2021. 3. 25.
  • textsms
[LeetCode] Two Sum

[LeetCode] Two Sum

Two Sum - LeetCode 숫자의 배열, 목표 숫자를 입력받고 배열 중 두 수를 골라서 더하면 목표 숫자가 나오는 두 수의 인덱스를 반환하라. class Solution { public int[] twoSum(int[] nums, int target) { int[] answer = new int[2]; for (int i = 0; i < nums.length; i++) { int num1 = nums[i]; for (int j = i + 1; j < nums.length; j++) { int num2 = nums[j]; if(num1 + num2 == target) { answer[0] = i; answer[1] = j; break; } } } return answer; } } 출처: LeetCo..

  • format_list_bulleted 알고리즘/LeetCode
  • · 2021. 3. 22.
  • textsms
  • navigate_before
  • 1
  • navigate_next
전체 카테고리
  • 분류 전체보기 (91)
    • Java (5)
      • Spring Boot (8)
    • DevOps (17)
      • Git (7)
      • Docker (2)
      • Jenkins (7)
    • Frontend (9)
      • Next.js (4)
      • React (4)
    • 알고리즘 (15)
      • 프로그래머스 (13)
      • LeetCode (2)
    • Dev (22)
      • Database (2)
      • GPT (4)
      • TIP (6)
      • AWS (10)
    • Etc (8)
      • 마시는인생 (3)
      • 구매&사용기 (2)
인기 글
최근 댓글
Copyright © 오이가지아빠 All rights reserved.
SKIN: Copyright © 쭈미로운 생활 All rights reserved. Designed by JJuum

티스토리툴바