In the function Solution::two_sum, the following code was added: ```rust for (i, v) in nums.iter().enumerate() { indices.insert(v, i); } ``` This fixes a bug and makes the code produce the correct output.

Code view:

A painting is a person's account of this edit as text, recorded independently of the node mapping - a rendering often has several equally defensible answers where the mapping has one. Deletions and insertions carry no position on the opposite side in a painting, so that panel draws no caret for them.

Before

1use std::collections::HashMap;
2
3impl Solution {
4 pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
5 let mut indices = HashMap::new();
6
7 for (i, v) in nums.iter().enumerate() {
8 let x = target - v;
9 let t = indices.get_key_value(&x);
10
11 match t {
12 Some((_, y)) => {
…lines 13–27 unchanged (15 lines)

After

1use std::collections::HashMap;
2
3impl Solution {
4 pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
5 let mut indices = HashMap::new();
6
7 for (i, v) in nums.iter().enumerate() {
8 indices.insert(v, i);
9 }
10
11 for (i, v) in nums.iter().enumerate() {
12 let x = target - v;
13 let t = indices.get_key_value(&x);
14
15 match t {
…lines 16–31 unchanged (16 lines)

Before

source_file
use_declaration
use "use"
scoped_identifier
scoped_identifier
identifier "std"
:: "::"
identifier "collections"
:: "::"
identifier "HashMap"
; ";"
impl_item
impl "impl"
type_identifier "Solution"
declaration_list
{ "{"
function_item
visibility_modifier
pub "pub"
fn "fn"
identifier "two_sum"
parameters
( "("
parameter
identifier "nums"
: ":"
generic_type
type_identifier "Vec"
type_arguments
< "<"
primitive_type "i32"
> ">"
, ","
parameter
identifier "target"
: ":"
primitive_type "i32"
) ")"
-> "->"
generic_type
type_identifier "Vec"
type_arguments
< "<"
primitive_type "i32"
> ">"
block
{ "{"
let_declaration
let "let"
mutable_specifier "mut"
identifier "indices"
= "="
call_expression
scoped_identifier
identifier "HashMap"
:: "::"
identifier "new"
arguments
( "("
) ")"
; ";"
expression_statement (+145 nodes collapsed)
expression_statement
return_expression
return "return"
call_expression
scoped_identifier
identifier "Vec"
:: "::"
identifier "new"
arguments
( "("
) ")"
; ";"
} "}"
} "}"

After

source_file
use_declaration
use "use"
scoped_identifier
scoped_identifier
identifier "std"
:: "::"
identifier "collections"
:: "::"
identifier "HashMap"
; ";"
impl_item
impl "impl"
type_identifier "Solution"
declaration_list
{ "{"
function_item
visibility_modifier
pub "pub"
fn "fn"
identifier "two_sum"
parameters
( "("
parameter
identifier "nums"
: ":"
generic_type
type_identifier "Vec"
type_arguments
< "<"
primitive_type "i32"
> ">"
, ","
parameter
identifier "target"
: ":"
primitive_type "i32"
) ")"
-> "->"
generic_type
type_identifier "Vec"
type_arguments
< "<"
primitive_type "i32"
> ">"
block
{ "{"
let_declaration
let "let"
mutable_specifier "mut"
identifier "indices"
= "="
call_expression
scoped_identifier
identifier "HashMap"
:: "::"
identifier "new"
arguments
( "("
) ")"
; ";"
expression_statement
for_expression
for "for"
tuple_pattern
( "("
identifier "i"
, ","
identifier "v"
) ")"
in "in"
call_expression
field_expression
call_expression
field_expression
identifier "nums"
. "."
field_identifier "iter"
arguments
( "("
) ")"
. "."
field_identifier "enumerate"
arguments
( "("
) ")"
block
{ "{"
expression_statement
call_expression
field_expression
identifier "indices"
. "."
field_identifier "insert"
arguments
( "("
identifier "v"
, ","
identifier "i"
) ")"
; ";"
} "}"
expression_statement (+145 nodes collapsed)
expression_statement
return_expression
return "return"
call_expression
scoped_identifier
identifier "Vec"
:: "::"
identifier "new"
arguments
( "("
) ")"
; ";"
} "}"
} "}"