프로그래머스 Lv.1 콜라츠 추측
개발자가 되기까지 (2023.08.16~2024.04.15)/[Algorithm] Programmers ver.Java2024. 1. 29. 09:49프로그래머스 Lv.1 콜라츠 추측

class Solution { public int solution(int num) { int answer = 0; if(num == 1) { return 0; }else { while (num != 1) { if (answer > 500) { return -1; } if(num % 2 == 0) { num = num / 2; } else { num = (num * 3) + 1; } answer++; } } return answer; } } test3에서 자꾸 실패해서 알아보니, 오버플로우가 생긴다면 음수인 경우에도 계속 계산을 진행하면서 int 범위를 넘어서기 때문에 정확한 계산을 할 수 없다고 한다. 그래서 int를 long으로 형변환해주었다. class Solution { public int solu..

프로그래머스 Lv.0 음양 더하기
개발자가 되기까지 (2023.08.16~2024.04.15)/[Algorithm] Programmers ver.Java2024. 1. 26. 12:02프로그래머스 Lv.0 음양 더하기

class Solution { public int solution(int[] absolutes, boolean[] signs) { int answer = 0; for(int i = 0; i < signs.length; i++) { if(!signs[i]) { absolutes[i] *= -1; } answer += absolutes[i]; } return answer; } }

프로그래머스 Lv.0 빈 배열에 추가, 삭제하기
개발자가 되기까지 (2023.08.16~2024.04.15)/[Algorithm] Programmers ver.Java2024. 1. 26. 11:44프로그래머스 Lv.0 빈 배열에 추가, 삭제하기

import java.util.*; class Solution { public int[] solution(int[] arr, boolean[] flag) { ArrayList list = new ArrayList (); for(int i = 0; i < flag.length; i++) { if(flag[i]) { for(int j = 0; j < arr[i] * 2; j++) { list.add(arr[i]); } }else { for(int j = 0; j < arr[i]; j++) { list.remove(list.size()-1); } } } int answer[] = new int [list.size()]; for(int i = 0; i < list.size(); i++) { answer[i] =..

프로그래머스 Lv.0 문자열 뒤집기
개발자가 되기까지 (2023.08.16~2024.04.15)/[Algorithm] Programmers ver.Java2024. 1. 25. 11:08프로그래머스 Lv.0 문자열 뒤집기

class Solution { public String solution(String my_string, int s, int e) { String answer = ""; int idx = 0; String revStr = new StringBuilder(my_string.substring(s, e+1)).reverse().toString(); for(int i = 0; i = s && i

개발자가 되기까지 (2023.08.16~2024.04.15)/[Spring] Basic Web2024. 1. 25. 03:11[Spring] 25. 회원가입

register.jsp 회원가입 E-mail Password Nickname SignUp MemberController.java package com.basicWeb.www.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import com.basicWeb.www.security.MemberVO; import com.bas..

728x90
반응형
image