djdj - HTMLify profile

djdj
471 Files
103458 Views
Latest files of /djdj/me/problems/leetcode
select distinct author_id as id from views
where author_id = viewer_id
order by id asc;
where author_id = viewer_id
order by id asc;
bool checkPerfectNumber(int num){
int i,s=0;
for(i=1;i<num/2+1;i++)
{
if(num%i==0){
s=s+i;
}
}
int i,s=0;
for(i=1;i<num/2+1;i++)
{
if(num%i==0){
s=s+i;
}
}
def isPowerOfTwo(self, n):
for i in range(0,31):
if n == 3**i:
return 1
return 0
for i in range(0,31):
if n == 3**i:
return 1
return 0
def convertTemperature(self, celsius):
f = 1.8 * celsius + 32
k = celsius + 273.15
return [k,f]
f = 1.8 * celsius + 32
k = celsius + 273.15
return [k,f]
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
for i in range(len(nums)):
for j in range(i + 1, len(nums)):
if ( nums[i] + nums[j] == target):
return [i, j]
def twoSum(self, nums: List[int], target: int) -> List[int]:
for i in range(len(nums)):
for j in range(i + 1, len(nums)):
if ( nums[i] + nums[j] == target):
return [i, j]
select firstName, lastName, city, state from Person
LEFT join Address
on person.personId = address.personId;
LEFT join Address
on person.personId = address.personId;
def convertToBase7(self, num):
if num == 0:
return "0"
s = []
minus = False
if num < 0:
num = num * (-1)
minus = True
if num == 0:
return "0"
s = []
minus = False
if num < 0:
num = num * (-1)
minus = True
select name,population,area from World
where area >= 3000000 or population >= 25000000;
where area >= 3000000 or population >= 25000000;
class Solution {
function divide($dividend, $divisor) {
if(intval($dividend/$divisor) > 2**31-1){
return intval(($dividend/$divisor)-1);
}
return intval($dividend/$divisor);
}
}
function divide($dividend, $divisor) {
if(intval($dividend/$divisor) > 2**31-1){
return intval(($dividend/$divisor)-1);
}
return intval($dividend/$divisor);
}
}
select email from person
group by email
having count(email) > 1;
group by email
having count(email) > 1;
Q1378_Replace_Employee_ID_With_The_Unique_Idendifier.sql
djdj/me/problems/leetcode/Q1378_Replace_Employee_ID_With_The_Unique_Idendifier.sql
select unique_id,name from Employees
left join EmployeeUNI
on Employees.id = EmployeeUNI.id;
left join EmployeeUNI
on Employees.id = EmployeeUNI.id;
def multiply(self, num1, num2):
num1 = int(num1)
num2 = int(num2)
a = num1 * num2
return str(a)
num1 = int(num1)
num2 = int(num2)
a = num1 * num2
return str(a)
select name,bonus from employee
left join bonus
on bonus.empId = employee.empId
where bonus<1000 or bonus is null;
left join bonus
on bonus.empId = employee.empId
where bonus<1000 or bonus is null;
select tweet_id from tweets
where length(content) > 15;
where length(content) > 15;
def findComplement(self, num):
s = []
while num > 0: # 5
r = str(num % 2)#
s.append(r)
num = num // 2
s = s[::-1]
b = "".join(d for d in s)
s = []
while num > 0: # 5
r = str(num % 2)#
s.append(r)
num = num // 2
s = s[::-1]
b = "".join(d for d in s)
def isPowerOfTwo(self, n):
for i in range(0,31):
if n == 2**i:
return 1
return 0
for i in range(0,31):
if n == 2**i:
return 1
return 0
select name from Customer where referee_id is null or referee_id != 2;
function mySqrt($x) {
return intval(sqrt($x));
}
return intval(sqrt($x));
}
def isPowerOfTwo(self, n):
for i in range(0,31):
if n == 4**i:
return 1
return 0
for i in range(0,31):
if n == 4**i:
return 1
return 0
select
(select distinct salary as SecondHighestSalary from Employee
order by salary desc limit 1,1) as SecondHighestSalary;
(select distinct salary as SecondHighestSalary from Employee
order by salary desc limit 1,1) as SecondHighestSalary;
Q1009_Complement_of_Base_10_Integer.py
djdj/me/problems/leetcode/Q1009_Complement_of_Base_10_Integer.py
def bitwiseComplement(self, num):
if num==0:
return 1
s = []
while num > 0:
r = str(num % 2)
s.append(r)
num = num // 2
if num==0:
return 1
s = []
while num > 0:
r = str(num % 2)
s.append(r)
num = num // 2
Q596_Classes_More_Than_5_Studeents.sql
djdj/me/problems/leetcode/Q596_Classes_More_Than_5_Studeents.sql
select class from courses
group by class
having count(class) >= 5
group by class
having count(class) >= 5
def sumOfMultiples(self,n):
s = 0
for i in range(1,n+1):
if i%3==0 or i%5==0 or i%7==0:
s = s + i
return s
s = 0
for i in range(1,n+1):
if i%3==0 or i%5==0 or i%7==0:
s = s + i
return s
def reverse(self, x):
if x > (2**30) or x < (-2**31)+1:
return 0
m = 0
if x < 0:
x = x * (-1)
m = 1
s = 0
if x > (2**30) or x < (-2**31)+1:
return 0
m = 0
if x < 0:
x = x * (-1)
m = 1
s = 0
class Solution(object):
def isPalindrome(self, x):
i = x
re = 0
"""
:type x: int
:rtype: bool
"""
def isPalindrome(self, x):
i = x
re = 0
"""
:type x: int
:rtype: bool
"""
def isSameAfterReversals(self, num):
t = num
s = 0
while num > 0: #526
r = num % 10 #6
s = s * 10 + r #6
num = num // 10 #52
s1 = 0
t = num
s = 0
while num > 0: #526
r = num % 10 #6
s = s * 10 + r #6
num = num // 10 #52
s1 = 0
select product_name,year,price from sales
inner join product
on sales.product_id = product.product_id;
inner join product
on sales.product_id = product.product_id;
Q1757_Recyclable_and_Low_Fat_Products.sql
djdj/me/problems/leetcode/Q1757_Recyclable_and_Low_Fat_Products.sql
select product_id from Products
where low_fats = 'Y' and recyclable = 'Y'
where low_fats = 'Y' and recyclable = 'Y'
var createHelloWorld = function() {
return function(...args) {
return "Hello World"
}
};
return function(...args) {
return "Hello World"
}
};
var createCounter = function(n) {
let c = n;
return function() {
return c++;
};
};
let c = n;
return function() {
return c++;
};
};
impl Solution {
pub fn add_digits(num: i32) -> i32 {
if(num==0){
return 0;
}
return (num-1)%9+1;
}
}
pub fn add_digits(num: i32) -> i32 {
if(num==0){
return 0;
}
return (num-1)%9+1;
}
}
Q2703_Return_Length_of_Arguments_Passed.js
djdj/me/problems/leetcode/Q2703_Return_Length_of_Arguments_Passed.js
var argumentsLength = function(...args) {
return args.length;
};
return args.length;
};
class Solution(object):
def sumBase(self, n, k):
s=0
while n > 0:
r = n%k
s = s+r
n=n//k
return s
def sumBase(self, n, k):
s=0
while n > 0:
r = n%k
s = s+r
n=n//k
return s
class Solution(object):
def isUgly(self, n):
if n == 1:
return 1
if n <=0:
return 0
for num in [2,3,5]:
while n % num == 0:
def isUgly(self, n):
if n == 1:
return 1
if n <=0:
return 0
for num in [2,3,5]:
while n % num == 0:
impl Solution {
pub fn common_factors(a: i32, b: i32) -> i32 {
let mut c=0;
for i in 1..a+b{
if(a%i==0 && b%i==0){
c=c+1;
}
}
pub fn common_factors(a: i32, b: i32) -> i32 {
let mut c=0;
for i in 1..a+b{
if(a%i==0 && b%i==0){
c=c+1;
}
}
class Solution(object):
def commonFactors(self, a, b):
c=0
for i in range(1,a+b):
if a%i==0 and b%i==0 :
c=c+1
return c
def commonFactors(self, a, b):
c=0
for i in range(1,a+b):
if a%i==0 and b%i==0 :
c=c+1
return c
public class Solution {
public int Sum(int num1, int num2) {
return num1 + num2;
}
}
public int Sum(int num1, int num2) {
return num1 + num2;
}
}
Q181_Employees_Earning_More_Than_Their_Managers.sql
djdj/me/problems/leetcode/Q181_Employees_Earning_More_Than_Their_Managers.sql
SELECT e.name AS Employee FROM Employee e, Employee a
WHERE e.managerID = a.id AND e.salary > a.salary;
WHERE e.managerID = a.id AND e.salary > a.salary;
Q1978_Employees_Whose_Manager_Left_the_Company.sql
djdj/me/problems/leetcode/Q1978_Employees_Whose_Manager_Left_the_Company.sql
SELECT employee_id FROM Employees
WHERE salary < 30000 and manager_id not in (SELECT employee_id FROM Employees)
ORDER BY(employee_id) ASC;
WHERE salary < 30000 and manager_id not in (SELECT employee_id FROM Employees)
ORDER BY(employee_id) ASC;
SELECT user_id, CONCAT(UPPER(LEFT(name,1)),LOWER(SUBSTRING(name,2))) AS name
FROM Users
ORDER BY user_id;
FROM Users
ORDER BY user_id;
select name as Customers from Customers
where id not in(select customerId from Orders);
where id not in(select customerId from Orders);