개발하는 쿠키
article thumbnail
Java, LeetCode | 35. Search Insert Position
Coding/algorithm 2024. 7. 23. 23:48

🚀 풀이 후기이진 탐색 문제를 오랜만에 푸니까 요령이 생겼습니다.항상 헷갈렸던 부분이 else if 구문에서 어느 조건에 answer 답변을 세팅해줘야 하는지였습니다.아래 문제에서 Example 2를 보면 nums[i]  일 때 answer = i+1 을 넣어주므로, 코드를 짤 때, target  nums[i] 인 조건에서 answer = i 를 세팅해주면 됩니다. 🌒 문제 설명Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You must..

article thumbnail
Java, BaekJoon | 27866. 문자와 문자열
Coding/algorithm 2024. 7. 23. 01:07

🚀 풀이 후기자바에서 String의 특정 index 에 있는 문자를 가져올 때 쓰는 함수는 `string.charAt(index)` 입니다.🌒 문제 설명🌓 문제 풀이import java.io.IOException;import java.io.BufferedReader;import java.io.InputStreamReader;public class Main{ public static void main(String[] args) throws IOException{ BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); String input = br.readLine(); ..

article thumbnail
Java, LeetCode | 27. Remove Element
Coding/algorithm 2024. 7. 23. 01:00

🚀 풀이 후기반환해야 하는 수 k를 "제거한 수의 개수" 로 잘못 해석했습니다.k = "제거하고 남은 수의 개수" 입니다.🌒 문제 설명Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val.Consider the number of elements in nums which are not equal to val be k, to get accepted, you need to do the foll..

article thumbnail
Java, BaekJoon | 31403. $A + B - C$
Coding/algorithm 2024. 7. 21. 13:29

🚀 풀이 후기오랜만에 알고리즘을 푸니까 BufferedReader, InputStreamReader로 인풋을 만드는 방법을 까먹었더라고요. 🥲🌒 문제 설명🌓 문제 풀이import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class Main { // 변수 A, B, C를 정의합니다. static int a, b, c; public static void main(String[] args) throws IOException { // BufferedReader를 이용해 A, B, C 를 입력받습니다. BufferedReader br = new Buffere..

article thumbnail
Java, LeetCode | 26. Remove Duplicates from Sorted Array
Coding/algorithm 2024. 7. 21. 13:02

🚀 풀이 후기정답인지 검사할 때, 함수의 반환 자료형인 int 의 값과, 인풋이었던 nums 를 모두 확인한다는 부분이 신기했습니다.🌒 문제 설명Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of unique elements in nums.Consider the number of unique elements of nums to be k, to get ac..

반응형