djdj - HTMLify profile
files of /djdj/me/problems/leetcode/
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 =
if num==0:
return 1
s = []
while num > 0:
r =
Q1050_Actor_and_Directors)Who_Cooperated_At_Least_Three_Times.sql
/djdj/me/problems/leetcode/Q1050_Actor_and_Directors)Who_Cooperated_At_Least_Three_Times.sql
select actor_id,director_id from ActorDirector
group by actor_id, director_id
Having count(actor_id = director_id) >=3;
group by actor_id, director_id
Having count(actor_id = director_id) >=3;
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;
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;
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;
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 tweet_id from tweets
where length(content) > 15;
where length(content) > 15;
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'
select firstName, lastName, city, state from Person
LEFT join Address
on person.personId = address.personId;
LEFT join Address
on person.personId = address.personId;
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;
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;
select email from person
group by email
having count(email) > 1;
group by email
having count(email) > 1;
class Solution(object):
def sumBase(self, n, k):
s=0
while n > 0:
r = n%k
s = s+r
def sumBase(self, n, k):
s=0
while n > 0:
r = n%k
s = s+r
select name as Customers from Customers
where id not in(select customerId from Orders);
where id not in(select customerId from Orders);
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(employ
WHERE salary < 30000 and manager_id not in (SELECT employee_id FROM Employees)
ORDER BY(employ
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
for i in range(len(nums)):
def twoSum(self, nums: List[int], target: int) -> List[int]:
for i in range(len(nums)):
def isSameAfterReversals(self, num):
t = num
s = 0
while num > 0: #526
r = num % 10 #6
s = s * 10 + r #6
t = num
s = 0
while num > 0: #526
r = num % 10 #6
s = s * 10 + r #6
public class Solution {
public int Sum(int num1, int num2) {
return num1 + num2;
}
}
public int Sum(int num1, int num2) {
return num1 + num2;
}
}
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
class Solution(object):
def commonFactors(self, a, b):
c=0
for i in range(1,a+b):
if a%i==0 and
def commonFactors(self, a, b):
c=0
for i in range(1,a+b):
if a%i==0 and
impl Solution {
pub fn common_factors(a: i32, b: i32) -> i32 {
let mut c=0;
for i in 1..a+b{
if(
pub fn common_factors(a: i32, b: i32) -> i32 {
let mut c=0;
for i in 1..a+b{
if(
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]
impl Solution {
pub fn add_digits(num: i32) -> i32 {
if(num==0){
return 0;
}
return (num
pub fn add_digits(num: i32) -> i32 {
if(num==0){
return 0;
}
return (num
var createCounter = function(n) {
let c = n;
return function() {
return c++;
};
};
let c = n;
return function() {
return c++;
};
};
class Solution(object):
def isUgly(self, n):
if n == 1:
return 1
if n <=0:
return 0
def isUgly(self, n):
if n == 1:
return 1
if n <=0:
return 0
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
Q2667_Create_Hello_World_Function.js
/djdj/me/problems/leetcode/Q2667_Create_Hello_World_Function.js
var createHelloWorld = function() {
return function(...args) {
return "Hello World"
}
};
return function(...args) {
return "Hello World"
}
};
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 {
function divide($dividend, $divisor) {
if(intval($dividend/$divisor) > 2**31-1){
return
function divide($dividend, $divisor) {
if(intval($dividend/$divisor) > 2**31-1){
return
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 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
bool isPerfectSquare(int num){
int r;
#include<math.h>
r = pow(num,0.5);
if(r*r==num)
{
return true;
int r;
#include<math.h>
r = pow(num,0.5);
if(r*r==num)
{
return true;
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)
def findComplement(self, num):
s = []
while num > 0: # 5
r = str(num % 2)#
s.append(r)
num = num // 2
s
s = []
while num > 0: # 5
r = str(num % 2)#
s.append(r)
num = num // 2
s
def convertToBase7(self, num):
if num == 0:
return "0"
s = []
minus = False
if num <
if num == 0:
return "0"
s = []
minus = False
if num <
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;
int fib(int n){
if(n==0)
return 0;
if(n==1)
return 1;
else
return fib(n-1)+fib(n-2);
}
if(n==0)
return 0;
if(n==1)
return 1;
else
return fib(n-1)+fib(n-2);
}
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 name from Customer where referee_id is null or referee_id != 2;
select name,population,area from World
where area >= 3000000 or population >= 25000000;
where area >= 3000000 or population >= 25000000;
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
function mySqrt($x) {
return intval(sqrt($x));
}
return intval(sqrt($x));
}
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