Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ketankr9/leetcode-solutions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

748 Commits

Repository files navigation

leetcode-solutions

Solutions to leetcode problems.

Below is the helper functions/aliases used by me to seamlessly fetch new questions, code it in atom, test and submit solution.

cat .env.sh

#!/bin/bash
LLANG="java"
EDITOR="sublime-text.subl"
LEETCODE='/home/user/.local/bin/leetcode'
_yargs_completions()
{
 local cur_word args type_list
 cur_word="${COMP_WORDS[COMP_CWORD]}"
 args=("${COMP_WORDS[@]}")
 # ask yargs to generate completions.
 type_list=$(../.local/bin/leetcode --get-yargs-completions "${args[@]}")
 COMPREPLY=( $(compgen -W "${type_list}" -- ${cur_word}) )
 # if no match was found, fall back to filename completion
 if [ ${#COMPREPLY[@]} -eq 0 ]; then
 COMPREPLY=( $(compgen -f -- "${cur_word}" ) )
 fi
 return 0
}
complete -F _yargs_completions leetcode
###-end-leetcode-completions-###
alias lee="$LEETCODE"
alias leetcode="$LEETCODE"
alias list='$LEETCODE list'
#alias submit='leetcode submit'
#alias commit='leetcode submit'
#alias show='leetcode show'
alias view='$LEETCODE view'
#alias star='leetcode star'
alias stat='$LEETCODE stat'
function show {
 "$LEETCODE" show "$@";
 ls -t | head -n1 > .lastAttempt;
}
function run {
	ls -t | head -n1 > .lastAttempt;
	echo "$(cat .lastAttempt)";
	if [ -z "1ドル" ];then
		"$LEETCODE" run "$(cat .lastAttempt | tr -d '\n')";
	else
		"$LEETCODE" run "$(cat .lastAttempt | tr -d '\n')" -t "$@";
	fi
}
function commit {
	ls -t | head -n1 > .lastAttempt;
	echo "$(cat .lastAttempt)";
	"$LEETCODE" submit "$(cat .lastAttempt | tr -d '\n')";
}
function star {
 Q="$(cat .lastAttempt | tr -d '\n')";
	if [ -z "1ドル" ]; then
		"$LEETCODE" star $(echo -n "${Q%%.*}");
	elif [ "1ドル" = "del" ]; then
		"$LEETCODE" star $(echo -n "${Q%%.*}") -d;
 else
 "$LEETCODE" star "$@";
	fi
}
function fetch {
 if [ -z "1ドル" ]; then
 Q="$(cat .lastAttempt | tr -d '\n')";
		"$LEETCODE" submission $(echo -n "${Q%%.*}");
	else
 out=$("$LEETCODE" submission "1ドル");
 echo "$out";
 if [ "$(echo -n $out | awk '{ print $NF }')" != "submissions?" ]; then
 $($EDITOR "$(echo -n $out | awk '{ print $NF }')");
 fi
	fi
}
function solution {
	Q="$(cat .lastAttempt | tr -d '\n')";
 echo "######## Java ########";
 "$LEETCODE" show $(echo -n "${Q%%.*}") --solution -l java;
 echo "######## cpp ########";
 "$LEETCODE" show $(echo -n "${Q%%.*}") --solution -l cpp;
}
function resume {
 Q="$(cat .lastAttempt | tr -d '\n')";
 "$LEETCODE" show $(echo -n "${Q%%.*}");
 $($EDITOR "$(cat .lastAttempt | tr -d '\n')");
}
alias startt="xterm -geometry 45x21-0+0 termdown &";
function restartTimer {
 pkill -f termdown
 xterm -geometry 48x27-0+0 termdown &
 # pkill -f leetimer
 # ./.leetimer.sh &
}
function solve {
 if [ -z "1ドル" ]; then
 resume;
 elif [ -z "2ドル" ] && [ ! -z "$(ls | grep -i "^1ドル\.")" ]; then
 "$EDITOR" "$(ls | grep -i "^1ドル\." | head -n1)";
 else
 "$LEETCODE" show "1ドル" -gx -e "${EDITOR}" -q D -l ${LLANG};
 fi
 restartTimer;
}
export -f run
export -f commit
alias submit='commit'
export -f show
export -f star
export -f solution
export -f resume
export -f solve
alias up='ls -t | head -n1 > .lastAttempt'

About

Solutions to leetcode problems, only accepted answers are commited.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /