-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
- Loading branch information
Showing
133 changed files
with
4,106 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,4 +104,4 @@ class Solution { | |
|
||
return array | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.