Merge Strings Alternately
·
알고리즘
문제는 아래와 같다. 대충 단어를 교차하여 조합해 보라는 말인 것 같다~~ 내가 푼 코드 class Solution { public String mergeAlternately(String word1, String word2) { int w1 = word1.length(); int w2 = word2.length(); StringBuilder sb = new StringBuilder(); int i = 0; while (i < w1 || i < w2) { if (i < w1) { sb.append(word1.charAt(i)); } if (i < w2) { sb.append(word2.charAt(i)); } i++; } return sb.toString(); } } 한줄씩 코드를 해석해 보자면 주어진 w..
자바, 자바스크립트 난수 생성 코드
·
알고리즘
파이널 프로젝트로 네이버 로그인을 구현 하던 중 16자리의 난수 생성이 필요 했다. 난수를 생성하는건 여러 방법이 있어 그 중에 두가지 방법을 소개 해보려고 한당 [Java] Random random = new Random(); String key = ""; for (int i = 0; i < 3; i++) { int index = random.nextInt(26) + 65; key += (char) index; } for (int i = 0; i < 6; i++) { int numIndex = random.nextInt(10); key += numIndex; } Random random = new Random() Random 클래스의 인스턴스를 생성하여 난수를 생성하기 위한 객체를 만든다. 이 객체를 ..
백준 2798번 블랙잭
·
알고리즘
package algorithm; import java.util.Scanner; public class algo_2798 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int n = sc.nextInt(); //카드개수 int m = sc.nextInt(); // 계산 최대값 int[] arr = new int[n]; // 들어 가는 갯수를 배열에 넣어주고 for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } // 그 수만큼 입력 받아 int result = 0; int temp = 0; for (int..
해니01_15
'알고리즘' 카테고리의 글 목록