-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# @lc code=start | ||
using LeetCode | ||
|
||
function strStr(haystack::String, needle::String) | ||
needle == "" && return 0 | ||
for i in 1:(length(haystack) - length(needle) + 1) | ||
if @view(haystack[i:(i + length(needle) - 1)]) == needle | ||
return i - 1 # Notice that Julia is 1-indexed, and here we need 0-indexed so minus 1 | ||
end | ||
end | ||
return -1 | ||
end | ||
|
||
function strStr2(haystack::AbstractString, needle::AbstractString) | ||
|
||
isempty(needle) && return 0 | ||
length(needle) > length(haystack) && return -1 | ||
|
||
needle == @view(haystack[1:length(needle)]) && return 0 | ||
|
||
ind = @views strStr2(haystack[2:end], needle) | ||
return ind == -1 ? -1 : ind + 1 | ||
end | ||
# @lc code=end | ||
|
||
# This file was generated using Literate.jl, https://github.com/fredrikekre/Literate.jl | ||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"Given two integers `dividend` and `divisor`, divide two integers without using\n", | ||
"multiplication, division, and mod operator.\n", | ||
"\n", | ||
"Return the quotient after dividing `dividend` by `divisor`.\n", | ||
"\n", | ||
"The integer division should truncate toward zero, which means losing its\n", | ||
"fractional part. For example, `truncate(8.345) = 8` and `truncate(-2.7335) =\n", | ||
"-2`.\n", | ||
"\n", | ||
"**Note:**\n", | ||
"\n", | ||
" * Assume we are dealing with an environment that could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For this problem, assume that your function **returns 2 31 − 1 when the division result overflows**.\n", | ||
"\n", | ||
"\n", | ||
"\n", | ||
"**Example 1:**\n", | ||
"\n", | ||
"\n", | ||
"\n", | ||
" Input: dividend = 10, divisor = 3\n", | ||
" Output: 3\n", | ||
" Explanation: 10/3 = truncate(3.33333..) = 3.\n", | ||
"\n", | ||
"\n", | ||
"**Example 2:**\n", | ||
"\n", | ||
"\n", | ||
"\n", | ||
" Input: dividend = 7, divisor = -3\n", | ||
" Output: -2\n", | ||
" Explanation: 7/-3 = truncate(-2.33333..) = -2.\n", | ||
"\n", | ||
"\n", | ||
"**Example 3:**\n", | ||
"\n", | ||
"\n", | ||
"\n", | ||
" Input: dividend = 0, divisor = 1\n", | ||
" Output: 0\n", | ||
"\n", | ||
"\n", | ||
"**Example 4:**\n", | ||
"\n", | ||
"\n", | ||
"\n", | ||
" Input: dividend = 1, divisor = 1\n", | ||
" Output: 1\n", | ||
"\n", | ||
"\n", | ||
"\n", | ||
"\n", | ||
"**Constraints:**\n", | ||
"\n", | ||
" * `-231 <= dividend, divisor <= 231 - 1`\n", | ||
" * `divisor != 0`" | ||
], | ||
"metadata": {} | ||
}, | ||
{ | ||
"outputs": [ | ||
{ | ||
"output_type": "execute_result", | ||
"data": { | ||
"text/plain": "divide (generic function with 1 method)" | ||
}, | ||
"metadata": {}, | ||
"execution_count": 1 | ||
} | ||
], | ||
"cell_type": "code", | ||
"source": [ | ||
"# @lc code=start\n", | ||
"using LeetCode\n", | ||
"\n", | ||
"function divide(dividend::Int, divisor::Int)::Int\n", | ||
" sign = (dividend < 0) ⊻ (divisor < 0)\n", | ||
" dividend, divisor = abs(dividend), abs(divisor)\n", | ||
" result = 0\n", | ||
" while dividend >= divisor\n", | ||
" shift = 0\n", | ||
" while dividend >= (divisor << shift)\n", | ||
" shift += 1\n", | ||
" end\n", | ||
" dividend -= divisor << (shift - 1)\n", | ||
" result += 1 << (shift - 1)\n", | ||
" end\n", | ||
" return sign ? -result : result\n", | ||
"end\n", | ||
"# @lc code=end" | ||
], | ||
"metadata": {}, | ||
"execution_count": 1 | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"---\n", | ||
"\n", | ||
"*This notebook was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*" | ||
], | ||
"metadata": {} | ||
} | ||
], | ||
"nbformat_minor": 3, | ||
"metadata": { | ||
"language_info": { | ||
"file_extension": ".jl", | ||
"mimetype": "application/julia", | ||
"name": "julia", | ||
"version": "1.10.4" | ||
}, | ||
"kernelspec": { | ||
"name": "julia-1.10", | ||
"display_name": "Julia 1.10.4", | ||
"language": "julia" | ||
} | ||
}, | ||
"nbformat": 4 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# @lc code=start | ||
using LeetCode | ||
|
||
function divide(dividend::Int, divisor::Int)::Int | ||
sign = (dividend < 0) ⊻ (divisor < 0) | ||
dividend, divisor = abs(dividend), abs(divisor) | ||
result = 0 | ||
while dividend >= divisor | ||
shift = 0 | ||
while dividend >= (divisor << shift) | ||
shift += 1 | ||
end | ||
dividend -= divisor << (shift - 1) | ||
result += 1 << (shift - 1) | ||
end | ||
return sign ? -result : result | ||
end | ||
# @lc code=end | ||
|
||
# This file was generated using Literate.jl, https://github.com/fredrikekre/Literate.jl | ||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# @lc code=start | ||
using LeetCode | ||
|
||
function countandsay(n::Int) | ||
|
||
n == 1 && return "1" | ||
|
||
previous_term = countandsay(n - 1) | ||
|
||
current_term = "" | ||
count = 0 | ||
current_char = previous_term[1] | ||
|
||
for char in previous_term | ||
if char == current_char | ||
count += 1 | ||
else | ||
current_term *= string(count) * current_char | ||
current_char = char | ||
count = 1 | ||
end | ||
end | ||
|
||
current_term * string(count) * current_char | ||
end | ||
# @lc code=end | ||
|
||
# This file was generated using Literate.jl, https://github.com/fredrikekre/Literate.jl | ||
|
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.