[JAVA] 프로그래머스 같은 숫자는 싫어

[JAVA] 프로그래머스 같은 숫자는 싫어

728x90

알고리즘

JAVA 프로그래머스 같은 숫자는 싫어

1. 문제

https://programmers.co.kr/learn/courses/30/lessons/12906

2. 풀이

크게 어려운 개념은 없었지만 for문, if문이 헷갈려서 정리해봤다. 원래는 배열의 앞뒤숫자를 비교해서 푸는 방법으로 먼저풀려고 했는데 잘 되지 않았다. 다른풀이로 다시 공부!

import java.util.*; class Solution { public int[] solution(int []arr) { // int[] arr = {1,1,3,3,0,1,1}; ArrayList tempList = new ArrayList(); int preNum = 10; //10이상의 숫자 아무거나(arr 원소가 9이하라서) //아래for문과 같음 // for (int num : arr) { // if (preNum != num) // tempList.add(num); // preNum = num; // } // tempList list에 넣어주기 for(int i=0; i

[다른사람의 풀이]

더 비효율적일 수도 있지만 풀려고 시도했던 풀이법으로 못풀면 답답....

import java.util.*; public class Solution { public int[] solution(int []arr) { int[] answer ; int count = 1; for(int i=1; i

728x90

from http://yuricoding.tistory.com/61 by ccl(A) rewrite - 2021-11-11 13:27:59