Skip to content

Instantly share code, notes, and snippets.

🍳
egg

nanja Y-kyoto

🍳
egg
Block or report user

Report or block Y-kyoto

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View leetcode_problem922.py
class Solution(object):
def sortArrayByParityII(self, A):
"""
:type A: List[int]
:rtype: List[int]
"""
evnvs, oddvs = [], []
for ai in A:
if ai%2==0:
View leetcode_problem412.cpp
class Solution {
public:
vector<string> fizzBuzz(int n) {
vector<string> res(n);
for(int i=0;i<n;i++){
int ip1 = i+1;
if(ip1%3==0 || ip1%5==0){
if(ip1%3==0)res[i]+="Fizz";
if(ip1%5==0)res[i]+="Buzz";
@Y-kyoto
Y-kyoto / leetcode_problem21.java
Created Sep 8, 2019
leetcode_problem21.java
View leetcode_problem21.java
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
View leetcode_problem20.cpp
class Solution {
public:
bool isValid(string s) {
stack<char> stk;
for (int i = 0; i < s.length(); i++) {
if ((s[i] == '(') || (s[i] == '[') || (s[i] == '{')) {
// 括弧の前半を見つけたらスタックに
stk.push(s[i]);
} else if (stk.size() == 0) {
@Y-kyoto
Y-kyoto / matplot_gif_example.py
Created Aug 17, 2019
matplitlibアニメーション生成例
View matplot_gif_example.py
from matplotlib import animation
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = Axes3D(fig)
def plot(X, Y, model=None, title="", option={}, fig=fig, ax=ax):
min_x = np.min(X[:, 0])
max_x = np.max(X[:, 0])
View leetcode_problem14.py
class Solution:
def longestCommonPrefix(self, strlist: List[str]) -> str:
prefix = ""
if len(strlist)==0:
return ""
elif len(strlist)==1:
return strlist[0]
else:
# 文字列リストの先頭文字列と1文字ずつ調べる
View leetcode_problem13.py
class Solution:
def romanToInt(self, s: str) -> int:
ss = [ "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"]
vs = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
ind = 0
res = 0
slen = len(s)
for sbl, val in zip( ss, vs ):
# 末尾に到達したなら終了
View leetcode_problem12.py
class Solution:
def intToRoman(self, num: int) -> str:
ss = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"]
vs = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
res = ""
for s, v in zip( ss, vs ):
if num==0: # 0ならば終了
break
elif num<v: # vよりも小さい値なら次へ
@Y-kyoto
Y-kyoto / leetcode_problem11.py
Last active Aug 16, 2019
leetcode_problem11
View leetcode_problem11.py
class Solution:
def maxArea(self, height: List[int]) -> int:
maxArea = 0
i, j, N = 0, 1, len(height)
while i+j<N:
if height[i] <= height[N-j]:
area = (N-i-j)*height[i]
i += 1
elif height[i] > height[N-j]:
View leetcode_problem9.py
class Solution:
def isPalindrome(self, x: int) -> bool:
if x is None:
return False
if x<0:
return False
else:
x = str(x)
res = True
# 左右対称かチェック、中央はチェック不要
You can’t perform that action at this time.