본문 바로가기

알고리즘

(25)
Two some_leet code #1 public int[] twoSum(int[] nums, int target) { if(nums==null || nums.length
(JAVA) 가장 큰 수 import java.util.ArrayList; import java.util.Collections; import java.util.List; class Solution { public String solution(int[] numbers) { String answer = ""; List list = new ArrayList(); for(int i = 0; i { String as = String.valueOf(a), bs = String.valueOf(b); return -Integer.compare(Integer.parseInt(as + bs), Integer.parseInt(bs + as)); }); StringBuilder sb = new StringBuilder(); for(Integer i ..
(JAVA) 탑 class Solution { public int[] solution(int[] heights) { int[] answer = new int[heights.length]; for(int i=heights.length-1; i>=0; i--) { for(int j=i-1; j>=0; j--) { if(heights[j] > heights[i]) { answer[i] = j+1; break; } } } return answer; }}-----------------import java.awt.Point; import java.util.Stack; class Solution { public int[] solution(int[] heights) { int[] answer = new int[heights.lengt..
(JAVA) 문자열을 정수로 바꾸기 class Solution { public int solution(String s) { return Integer.parseInt(s); } }---------------------------------public class StrToInt { public int getStrToInt(String str) { boolean Sign = true; int result = 0; for (int i = 0; i
(JAVA) 수박수박수박수박수박수? class Solution { public String solution(int n) { String answer = ""; for(int i=0; i
(JAVA) 소수 찾기 참조하세요 class Solution { int solution(int n) { int cnt = 0; int answer = 0; for(int i = 1 ; i
(JAVA) 서울에서 김서방 찾기 import java.util.Map; import java.util.HashMap; class Solution { public String solution(String[] seoul) { int cnt=0; Map map = new HashMap(); for(String check:seoul){ map.put(check,cnt); cnt++; } return "김서방은 "+map.get("Kim")+"에 있다"; } }-------------------------------------public class FindKim { public String findKim(String[] seoul){ return "김서방은 "+ Arrays.asList(seoul).indexOf("Kim") + "에 있다"; ..
(JAVA) 문자열 다루기 기본 class Solution { public boolean solution(String s) { boolean answer = false; int check = s.length(); if(check==4||check==6){ if(s.matches("^\\d+$")){ return true; } } return answer; } }-----------------class Solution { public boolean solution(String s) { if(s.length() == 4 || s.length() == 6){ try{ int x = Integer.parseInt(s); return true; } catch(NumberFormatException e){ return false; } } else..