10일차 데일리 과제

IIRU·2026년 5월 28일

7의 개수

https://school.programmers.co.kr/learn/courses/30/lessons/120912

using System;

public class Solution {
    public int solution(int[] array) {
        int answer = 0;
        
        for(int i=0; i<array.Length; i++){
            while(array[i] > 0){
                if(array[i]%10 == 7){
                    answer++;
                }
                array[i]/=10;
            }
        }
        
        return answer;
    }
}

제일 작은 수 제거하기

https://school.programmers.co.kr/learn/courses/30/lessons/12935

public class Solution {
    public int[] solution(int[] arr) {
        int[] answer = new int[] {};
        
        int min = arr[0];
        for(int i = 1; i<arr.Length; i++){
            if(min > arr[i]){
                min = arr[i];
            }
        }
        
        if(arr.Length == 1){
            int[] temp = new int[1];
            temp[0] = -1;
            answer = temp;
        }
        else{
            int index = 0;
            int[] temp = new int[arr.Length-1];
            for(int i=0; i<arr.Length; i++){
                if(min != arr[i]){
                    temp[index] = arr[i];
                    index++;
                }
            }
            answer = temp;
        }
        
        
        
        return answer;
    }
}

중복된 문자 제거

https://school.programmers.co.kr/learn/courses/30/lessons/120888

using System;
using System.Text;

public class Solution {
    public string solution(string my_string) {
        string answer = "";
        
        StringBuilder sb = new StringBuilder();
        
        int[] upper = new int[26];
        int[] lower = new int[26];
        bool space = false;
        
        for(int i=0; i<my_string.Length; i++){
            if(my_string[i] >= 'a' && my_string[i] <= 'z'){
                if(upper[my_string[i]-'a'] < 1){
                    sb.Append(my_string[i]);
                }
                upper[my_string[i]-'a']++;
            }
            else if(my_string[i] >= 'A' && my_string[i] <= 'Z'){
                if(lower[my_string[i] -'A'] < 1){
                    sb.Append(my_string[i]);
                }
                lower[my_string[i]-'A']++;
            }
            else if(my_string[i] == ' '){
                if(space == false){
                    sb.Append(my_string[i]);
                }
                space = true;
            }
        }
        answer = sb.ToString(); 
        
        return answer;
    }
}
profile
초보 개발자 블로그입니다!

0개의 댓글