GeniusOfCX

导航

2021年4月8日 #

leetcode 28 rust

摘要: 题目 代码 pub fn str_str(haystack: String, needle: String) -> i32 { let hay_len = haystack.len() as i32; let ned_len = needle.len() as i32; if hay_len < n 阅读全文

posted @ 2021-04-08 16:24 GeniusOfCX 阅读(43) 评论(0) 推荐(0) 编辑

leetcode 153 rust

摘要: 题目 代码 pub fn find_min(nums: Vec<i32>) -> i32 { let mut left = 0_i32; let mut right = (nums.len() as i32) - 1; let mut mid; while left <= right { if nu 阅读全文

posted @ 2021-04-08 16:21 GeniusOfCX 阅读(29) 评论(0) 推荐(0) 编辑

leetcode 456 rust

摘要: 题目 代码 pub fn find132pattern(nums: Vec<i32>) -> bool { let mut mn = nums[0]; let mut vec:Vec<(i32,i32)> = Vec::new(); for &num in nums.iter().skip(1){ 阅读全文

posted @ 2021-04-08 13:50 GeniusOfCX 阅读(86) 评论(0) 推荐(0) 编辑

leetcode 35 rust

摘要: 题目 代码 pub fn search_insert(nums: Vec<i32>, target: i32) -> i32 { let mut left = 0; let mut right = nums.len()-1; let mut mid; while left <= right { mi 阅读全文

posted @ 2021-04-08 13:48 GeniusOfCX 阅读(30) 评论(0) 推荐(0) 编辑

leetcode 34 rust

摘要: 题目 代码 pub fn search_range(nums: Vec<i32>, target: i32) -> Vec<i32> { let lower = lower_bound(&nums,target); let upper = upper_bound(&nums,target); if 阅读全文

posted @ 2021-04-08 13:47 GeniusOfCX 阅读(43) 评论(0) 推荐(0) 编辑

leetcode 2 rust

摘要: 题目 代码 pub fn add_two_numbers(l1: Option<Box<ListNode>>, l2: Option<Box<ListNode>>) -> Option<Box<ListNode>> { let mut result = None; let mut temp = &m 阅读全文

posted @ 2021-04-08 13:42 GeniusOfCX 阅读(34) 评论(0) 推荐(0) 编辑

leetcode 1 rust

摘要: 题目 代码 pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> { let len = nums.len(); let mut a:Vec<i32> = vec![0;len]; for i in 0..len { for j in 0 . 阅读全文

posted @ 2021-04-08 13:41 GeniusOfCX 阅读(46) 评论(0) 推荐(0) 编辑

leetcode 20 rust

摘要: 题目 编程语言 rust 注意点 字符也可以用==,!= 代码 pub fn is_valid(s: String) -> bool { let mut p = Vec::new(); for i in s.chars() { match i { '[' => p.push(']'), '(' => 阅读全文

posted @ 2021-04-08 13:34 GeniusOfCX 阅读(36) 评论(0) 推荐(0) 编辑

leetcode 287 rust

摘要: 题目 编程语言 rust 注意点 原地置换法:原地置换的总体思路就是将我们的元素放到他的索引位置。我们可以这样理解,每个人都有自己的位置,我们需要和别人调换回到属于自己的位置,调换之后,如果发现我们的位置上有人了,则返回。算法来源 代码 pub fn find_duplicate(nums: Vec 阅读全文

posted @ 2021-04-08 13:19 GeniusOfCX 阅读(59) 评论(0) 推荐(0) 编辑

leetcode 18 rust

摘要: 题目 编程语言 rust 注意点 同leetcode15 代码 pub fn four_sum(nums: Vec<i32>, target: i32) -> Vec<Vec<i32>> { let mut res : Vec<Vec<i32>> = Vec::new(); if nums.len( 阅读全文

posted @ 2021-04-08 10:16 GeniusOfCX 阅读(45) 评论(0) 推荐(0) 编辑