프로그래밍/리트코드(Rust)

1. Two Sum

roquen4145 2022. 4. 28.

문제

https://leetcode.com/problems/two-sum/

 

Two Sum - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

풀이

impl Solution {
    pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
        let mut answer = Vec::new();
        for i in 0..nums.len() {
            for j in (i+1)..nums.len() {
                if nums[i] + nums[j] == target {
                    answer.push(i as i32);
                    answer.push(j as i32);
                    break;
                }
            }
        }
        answer
    }
}

댓글