-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5eaa836
commit 1cb0f6f
Showing
13 changed files
with
171 additions
and
111 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* @lc app=leetcode.cn id=221 lang=rust | ||
* | ||
* [221] 最大正方形 | ||
*/ | ||
|
||
// @lc code=start | ||
impl Solution { | ||
pub fn maximal_square(matrix: Vec<Vec<char>>) -> i32 { | ||
let mut res = 0; | ||
let mut val = 0; | ||
let row = matrix.len(); | ||
let column = matrix[0].len(); | ||
for i in 0..row { | ||
for j in 0..column { | ||
let current_val = matrix[i][j]; | ||
let right = j + 1; | ||
let down = i + 1; | ||
while right < column && down < row {} | ||
} | ||
} | ||
} | ||
} | ||
// @lc code=end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* @lc app=leetcode.cn id=825 lang=rust | ||
* | ||
* [825] 适龄的朋友 | ||
*/ | ||
|
||
// @lc code=start | ||
impl Solution { | ||
pub fn num_friend_requests(ages: Vec<i32>) -> i32 { | ||
|
||
} | ||
} | ||
// @lc code=end | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,89 @@ | ||
// 一维数组 | ||
/* | ||
* @lc app=leetcode.cn id=413 lang=rust | ||
* @lc app=leetcode.cn id=221 lang=rust | ||
* | ||
* [413] 等差数列划分 | ||
* [221] 最大正方形 | ||
*/ | ||
struct Solution {} | ||
// @lc code=start | ||
impl Solution { | ||
pub fn number_of_arithmetic_slices(nums: Vec<i32>) -> i32 { | ||
let n = nums.len(); | ||
let mut dp = vec![false; n]; | ||
pub fn maximal_square(matrix: Vec<Vec<char>>) -> i32 { | ||
let row = matrix.len(); | ||
let column = matrix[0].len(); | ||
let mut dp = vec![vec![0; column]; row]; | ||
let mut res = 0; | ||
dp[0] = true; | ||
for i in 0..n { | ||
for j in (i + 1)..n { | ||
if j - i <= 1 { | ||
dp[j] = true; | ||
continue; | ||
} | ||
dp[j] = if dp[j - 1] && nums[j] - nums[j - 1] == nums[j - 1] - nums[j - 2] { | ||
true | ||
} else { | ||
false | ||
}; | ||
if dp[j] && j >= 2 { | ||
res = res + 1; | ||
for i in 0..row { | ||
for j in 0..column { | ||
if matrix[i][j] == '1' { | ||
if i == 0 || j == 0 { | ||
dp[i][j] = 1; | ||
} else { | ||
dp[i][j] = dp[i - 1][j].min(dp[i][j - 1].min(dp[i - 1][j - 1])) + 1 | ||
} | ||
} | ||
res = res.max(dp[i][j]) | ||
} | ||
} | ||
res | ||
res * res | ||
} | ||
} | ||
// @lc code=end | ||
// pub fn maximal_square(matrix: Vec<Vec<char>>) -> i32 { | ||
// let mut res = 0; | ||
// let row = matrix.len(); | ||
// let column = matrix[0].len(); | ||
// for i in 0..row { | ||
// for j in 0..column { | ||
// if matrix[i][j] != '1' { | ||
// continue; | ||
// } | ||
// let mut right = j + 1; | ||
// let mut down = i + 1; | ||
|
||
// while right < column && down < row { | ||
// if Solution::check(&matrix, (i, j, right, down)) { | ||
// res = res.max((down - i + 1) * (right - j + 1)); | ||
// right = right + 1; | ||
// down = down + 1; | ||
// } else { | ||
// break; | ||
// } | ||
// } | ||
// res = res.max(1) | ||
// } | ||
// } | ||
// res as i32 | ||
// } | ||
// fn check(matrix: &Vec<Vec<char>>, coords: (usize, usize, usize, usize)) -> bool { | ||
// let (top, left, right, down) = coords; | ||
// if matrix[down][right] != '1' { | ||
// return false; | ||
// } | ||
// for i in left..right { | ||
// if matrix[down][i] != '1' { | ||
// return false; | ||
// } | ||
// } | ||
// for i in top..down { | ||
// if matrix[i][right] != '1' { | ||
// return false; | ||
// } | ||
// } | ||
// true | ||
// } | ||
} | ||
// @lc code=end | ||
#[cfg(test)] | ||
|
||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn tests() { | ||
fn name() { | ||
println!( | ||
"{:?}", | ||
Solution::number_of_arithmetic_slices(vec![1, 2, 3, 4]) | ||
); | ||
println!("{:?}", Solution::number_of_arithmetic_slices(vec![1])) | ||
"{}", | ||
Solution::maximal_square(vec![ | ||
vec!['1', '1', '0'], | ||
vec!['1', '1', '1'], | ||
vec!['1', '1', '1'], | ||
vec!['1', '1', '0'] | ||
]) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "leetcodebyrust" | ||
version = "0.1.0" | ||
authors = ["zhangyuang <yuuang>"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// 一维数组 | ||
/* | ||
* @lc app=leetcode.cn id=413 lang=rust | ||
* | ||
* [413] 等差数列划分 | ||
*/ | ||
struct Solution {} | ||
// @lc code=start | ||
impl Solution { | ||
pub fn number_of_arithmetic_slices(nums: Vec<i32>) -> i32 { | ||
let n = nums.len(); | ||
let mut dp = vec![false; n]; | ||
let mut res = 0; | ||
dp[0] = true; | ||
for i in 0..n { | ||
for j in (i + 1)..n { | ||
if j - i <= 1 { | ||
dp[j] = true; | ||
continue; | ||
} | ||
dp[j] = if dp[j - 1] && nums[j] - nums[j - 1] == nums[j - 1] - nums[j - 2] { | ||
true | ||
} else { | ||
false | ||
}; | ||
if dp[j] && j >= 2 { | ||
res = res + 1; | ||
} | ||
} | ||
} | ||
res | ||
} | ||
} | ||
// @lc code=end | ||
|
||
// @lc code=end | ||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn tests() { | ||
println!( | ||
"{:?}", | ||
Solution::number_of_arithmetic_slices(vec![1, 2, 3, 4]) | ||
); | ||
println!("{:?}", Solution::number_of_arithmetic_slices(vec![1])) | ||
} | ||
} |