Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
keunsun.lee committed Aug 19, 2024
2 parents 91e33fc + d19b3de commit e29c515
Show file tree
Hide file tree
Showing 133 changed files with 4,106 additions and 3 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: ๐Ÿ”„ Integration

on:
pull_request:

jobs:
linelint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: fernandrone/[email protected]
18 changes: 18 additions & 0 deletions .linelint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 'true' will fix files
autofix: false

# list of paths to ignore, uses gitignore syntaxes (executes before any rule)
ignore:
- "*.md"

rules:
# checks if file ends in a newline character
end-of-file:
# set to true to enable this rule
enable: true

# set to true to disable autofix (if enabled globally)
disable-autofix: false

# if true also checks if file ends in a single newline character
single-new-line: false
2 changes: 1 addition & 1 deletion binary-tree-level-order-traversal/WhiteHyun.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ class Solution {

return array
}
}
}
8 changes: 8 additions & 0 deletions contains-duplicate/0-chan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* time complexity : O(n)
* space complexity : O(n)
*/
function containsDuplicate(nums: number[]): boolean {
const hasDuplicate = new Set(nums).size !== nums.length;
return hasDuplicate;
};
60 changes: 60 additions & 0 deletions contains-duplicate/EGON.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from unittest import TestCase, main
from typing import List
from collections import Counter


class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
return self.solve_3(nums=nums)

"""
Runtime: 412 ms (Beats 75.17%)
Analyze Complexity: O(n)
Memory: 31.92 MB (Beats 45.93%)
"""
def solve_1(self, nums: List[int]) -> bool:
return len(nums) != len(set(nums))

"""
Runtime: 423 ms (Beats 39.66%)
Analyze Complexity: O(n)
Memory: 34.54 MB (Beats 14.97%)
"""
def solve_2(self, nums: List[int]) -> bool:
counter = {}
for num in nums:
if num in counter:
return True
else:
counter[num] = True
else:
return False

"""
Runtime: 441 ms (Beats 16.59%)
Analyze Complexity: O(n)
Memory: 34.57 MB (Beats 14.97%)
"""
def solve_3(self, nums: List[int]) -> bool:
return Counter(nums).most_common(1)[0][1] > 1


class _LeetCodeTCs(TestCase):
def test_1(self):
nums = [1, 2, 3, 1]
output = True
self.assertEqual(Solution.containsDuplicate(Solution(), nums=nums), output)

def test_2(self):
nums = [1, 2, 3, 4]
output = False
self.assertEqual(Solution.containsDuplicate(Solution(), nums=nums), output)

def test_3(self):
nums = [1, 1, 1, 3, 3, 4, 3, 2, 4, 2]
output = True
self.assertEqual(Solution.containsDuplicate(Solution(), nums=nums), output)


if __name__ == '__main__':
main()
34 changes: 34 additions & 0 deletions contains-duplicate/EGON.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Foundation

class Solution {
func containsDuplicate(_ nums: [Int]) -> Bool {
return solve_2(nums)
}

/*
Runtime: 246 ms (Beats 68.44%)
Analyze Complexity: O(n)
Memory: 19.94 MB (Beats 76.01%)
*/
func solve_1(_ nums: [Int]) -> Bool {
return nums.count != Set(nums).count
}

/*
Runtime: 240 ms (Beats 90.56%)
Analyze Complexity: O(n)
Memory: 22.56 MB (Beats 33.43%)
*/
func solve_2(_ nums: [Int]) -> Bool {
var counter: [Int: Bool] = [:]
for num in nums {
if counter[num] != nil {
return true
} else {
counter[num] = true
}
}

return false
}
}
14 changes: 14 additions & 0 deletions contains-duplicate/GUMUNYEONG.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @param {number[]} nums
* @return {boolean}
*/
var containsDuplicate = function (nums) {
const setObj = new Set(nums);

const diff = !(nums.length === setObj.size);

return diff;
};

// TC: O(n)
// SC: O(n)
21 changes: 21 additions & 0 deletions contains-duplicate/HC-kang.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
217. Contains Duplicate
Example 1:
Input: nums = [1,2,3,1]
Output: true
Example 2:
Input: nums = [1,2,3,4]
Output: false
Example 3:
Input: nums = [1,1,1,3,3,4,3,2,4,2]
Output: true
*/

// Time complexity: O(n)
// Space complexity: O(n)
function containsDuplicate(nums: number[]): boolean {
return nums.length !== new Set(nums).size;
}
12 changes: 12 additions & 0 deletions contains-duplicate/Raft.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
appeared = defaultdict(int)
for n in nums:
if appeared[n] > 0:
return True
appeared[n] += 1

return False
# T: O(n)
# S: O(n)

17 changes: 17 additions & 0 deletions contains-duplicate/TonyKim9401.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public boolean containsDuplicate(int[] nums) {
// HashSet O(n)
/*
Set<Integer> set = new HashSet();
for (int num : nums) set.add(num);
return set.size() != nums.length;
*/

// dupl value O(n log n)
Arrays.sort(nums);
for (int i = 0; i < nums.length - 1; i++) {
if (nums[i] == nums[i + 1]) return true;
}
return false;
}
}
10 changes: 10 additions & 0 deletions contains-duplicate/bemelon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
# Time Complexity: O(n)
# Space Complexity: O(n)
seen = set()
for num in nums:
if num in seen:
return True
seen.add(num)
return False
6 changes: 6 additions & 0 deletions contains-duplicate/dm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from typing import List


class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
return len(nums) != len(set(nums))
24 changes: 24 additions & 0 deletions contains-duplicate/flynn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* for given size of input nums N,
*
* Time complexity: O(N)
* - iteration: O(N)
* - unorderd_set find method: O(1) on average
* - unorderd_set insert method: O(1) on average
*
* Space complexity: O(N)
*/

class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
unordered_set<int> unique_numbers;

auto it = nums.begin();
while (it != nums.end()) {
if (unique_numbers.find(*it) == unique_numbers.end()) unique_numbers.insert(*(it++));
else return true;
}
return false;
}
};
8 changes: 8 additions & 0 deletions contains-duplicate/gitsunmin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* https://leetcode.com/problems/contains-duplicate/
* time complexity : O(n)
* space complexity : O(n)
*/
function containsDuplicate(nums: number[]): boolean {
return new Set(nums).size !== nums.length
};
18 changes: 18 additions & 0 deletions contains-duplicate/haklee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""TC: O(n)? O(n^2)?, SC: O(n)
ref: https://wiki.python.org/moin/TimeComplexity
set๋Š” dict์™€ ๊ฑฐ์˜ ๋น„์Šทํ•˜๊ฒŒ ๊ตฌํ˜„๋˜์–ด ์žˆ๋Š”๋ฐ,
dict์˜ `Set Item`์˜ Average Case๋Š” O(1)์ด๋”๋ผ๋„
Amortized Worst Case๊ฐ€ O(n)์ด๋‹ค!
์ฆ‰, set์— ์•„์ดํ…œ์„ ์ถ”๊ฐ€ํ• ๋•Œ๋งˆ๋‹ค ํ•ด์‹œ ์ถฉ๋Œ์ด ์ผ์–ด๋‚  ๊ฒฝ์šฐ
์ตœ์•…์˜ ๊ฒฝ์šฐ O(n^2)์ด ๊ฑธ๋ฆฌ๋ฏ€๋กœ, ์•„๋ž˜์˜ set(nums)์˜
TC๊ฐ€ O(n^2)์ด ๋˜๋Š” ๊ฒƒ์ผ๊นŒ..?
set(nums)์˜ ๊ฒฐ๊ณผ๊ฐ€ ์ตœ์•…์˜ ๊ฒฝ์šฐ SC๊ฐ€ O(n)์ด๋‹ค.
"""


class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
return len(nums) != len(set(nums))
20 changes: 20 additions & 0 deletions contains-duplicate/heozeop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Time Complexity : O(n)
// Spatial Complexity : O(n)

#include <set>

class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
set<int> count;

for(int num : nums) {
if (count.find(num) != count.end()) {
return true;
}
count.insert(num);
}

return false;
}
};
10 changes: 10 additions & 0 deletions contains-duplicate/hwanminini.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// ์‹œ๊ฐ„๋ณต์žก๋„: O(n)
// ๊ณต๊ฐ„๋ณต์žก๋„: O(n)

/**
* @param {number[]} nums
* @return {boolean}
*/
var containsDuplicate = function(nums) {
return nums.length !== new Set(nums).size
};
16 changes: 16 additions & 0 deletions contains-duplicate/hyejjun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @param {number[]} nums
* @return {boolean}
*/
var containsDuplicate = function (nums) {

const set = new Set(nums);

return nums.length !== set.size ? true : false;

};


console.log(containsDuplicate([1, 2, 3, 1])); // true
console.log(containsDuplicate([1, 2, 3, 4])); // false
console.log(containsDuplicate([1, 1, 1, 3, 3, 4, 3, 2, 4, 2])); // true
16 changes: 16 additions & 0 deletions contains-duplicate/jaejeong1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

class SolutionJaeJeong1 {
public boolean containsDuplicate(int[] nums) {
// ํ•ด์‹œ๋งต ์‚ฌ์šฉํ•ด์„œ ๊ฐ™์€ ๊ฐ’์˜ ์นด์šดํŠธ๊ฐ€ 1๋ณด๋‹ค ํฌ๋ฉด true ๋ฐ˜ํ™˜
// ๋๊นŒ์ง€ ๋‹ค ๋Œ๋ฉด false ๋ฐ˜ํ™˜
// ๋˜๋Š” ํ•ด์‹œ์…‹ ์‚ฌ์šฉํ•ด์„œ ๋ชจ๋‘ ํ•ด์‹œ์…‹์— ๋„ฃ๊ณ 
// ๊ธธ์ด ๋น„๊ตํ•ด์„œ ๊ฐ™์œผ๋ฉด false, ๋‹ค๋ฅด๋ฉด true ๋ฐ˜ํ™˜
// ์‹œ๊ฐ„๋ณต์žก๋„: O(N), ๊ณต๊ฐ„๋ณต์žก๋„: O(N)

Set<Integer> set = Arrays.stream(nums).collect(HashSet::new, Set::add, Set::addAll);
return set.size() != nums.length;
}
}
Loading

0 comments on commit e29c515

Please sign in to comment.