function leetcode1461()
local paths = {
{
"B", "C" }, {
"D", "B" }, {
"C", "A" } }
local hash = {
}
for i, v in ipairs(paths) do
local key = v[1];
local value = v[2];
hash[key] = value;
end
local cur_key = paths[1][1];
while table.contains_key(hash, cur_key) do
cur_key = hash[cur_key];
end
return cur_key
end
function leetcode657()
local moves = "UD";
local arr = string.to_char_arr(moves);
local f = function(char)
return #table.find_all(arr, function(item)
return item == char;
end)
end
local bo1 = f("U") == f("D");
local bo2 = f("L") == f("R");
return bo1 and bo2;
end
function leetcode1299()
local arr = {
17, 18, 5, 4, 6, 1 }
local max = -1;
for i = #arr, 1, -1 do
local item = arr[i];
arr[i] = max;
if item > max then
max = item;
end
end
return arr;
end
function leetcode1351()
local grid = {
{
4, 3, 2, -1 },
{
3, 2, 1, -1 },
{
1, 1, -1, -2 },
{
-1, -1, -2, -3 },
}
local row =
用Lua刷LeetCode代码
最新推荐文章于 2021-02-27 02:01:21 发布