程式語言 - LeetCode - Rust - 1. Two Sum



參考資訊:
https://medium.com/@AlexanderObregon/solving-the-two-sum-problem-on-leetcode-rust-solutions-walkthrough-26a2e8b48616

題目:


解答:

impl Solution {
    pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
        for c0 in 0..nums.len() {
            for c1 in (c0 + 1)..nums.len() {
                if ((nums[c0] + nums[c1]) == target) {
                    return vec![c0 as i32, c1 as i32];
                }
            }
        }
        vec![]
    }
}