본문 바로가기

Java440

[LeetCode/Java] 58. Length of Last Word -Codeclass Solution { public int lengthOfLastWord(String s) { // 스페이스를 기준으로 나눠서 배열 생성 String[] strList = s.split(" "); // 리스트의 마지막 문자열 가져옴 String lastStr = strList[strList.length - 1]; // 마지막 문자열의 길이 반환 return lastStr.length(); }} 2025. 11. 20.
[LeetCode/Java] 35. Search Insert Position -Codeclass Solution { public int searchInsert(int[] nums, int target) { for(int i = 0; i = target) return i; } // 조건에 걸리지 않으면 마지막 index이므로 길이만큼 반환 return nums.length; }} 2025. 11. 20.
[LeetCode/Java] 28. Find the Index of the First Occurrence in a String -Codeclass Solution { public int strStr(String haystack, String needle) { int haystackLen= haystack.length(); int needleLen = needle.length(); for (int i = 0; i 2025. 11. 20.
[백준/Java] 2252번 줄 세우기 -Codeimport java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.*;public class BOJ2252 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseIn.. 2025. 11. 20.
[백준/Java] 34750번 추석은 언제나 좋아 -Codeimport java.util.Scanner;public class BOJ34750 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int money = sc.nextInt(); System.out.println(solution(money)); } static String solution(int money) { double el1 = money; double el2 = money; // 돈에 따른 조건문 if (money >= 1000000) { el1 *= 0.2; .. 2025. 11. 20.
[LeetCode/Java] 21. Merge Two Sorted Lists -Code/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.next = next; } * } */class Solution { public ListNode mergeTwoLists(ListNode list1, ListNode list2) { // 실제 결과의 포인터 ListNode answer = new ListNode(.. 2025. 11. 19.