削除最小数(C++、Python)

3261 ワード

最小数を削除

C++

#include <string>
#include <vector>
#include <iostream>
using namespace std;

vector<int> solution(vector<int> arr) {
    vector<int> answer;
    int n = arr[0];
    int m = 0;
    int l = size(arr);
    if(size(arr)==1) {
        answer.push_back(-1);
    } 
    else {
        for (int i = 1; i <l; i++) {
            if (n > arr[i]) {
                n = arr[i];
                m = i;
            }
        }
    
        arr.erase(arr.begin() + m );
        answer = arr;
    }
    
    return answer;
}

Python

def solution(arr):
    answer = []
    if len(arr)==1:
        answer.append(-1)
    else :
        m=min(arr)
        arr.remove(m)
        answer=arr
    return answer