Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions modulo6/complexidade-de-algoritmos/exercicio1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const findFirstRecurringCharacter = (input) => {
const charHashMap = {};
for (const char of input) {
if (charHashMap[char] === true) {
return char;
}
charHashMap[char] = true;
}
return null;
};

// Complexidade O(n)
24 changes: 24 additions & 0 deletions modulo6/complexidade-de-algoritmos/exercicio2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const func = (
source: string,
comparison: string
): boolean => {
if (
comparison.length > source.length + 1 ||
comparison.length < source.length - 1
) {
return false;
}
let commonCharQuantity = 0;

for (const char of comparison) {
if (source !== comparison) {
commonCharQuantity++;
}
}
return (
commonCharQuantity <= source.length + 1 &&
commonCharQuantity >= source.length - 1
);
};

// O(n)
17 changes: 17 additions & 0 deletions modulo6/complexidade-de-algoritmos/exercicio3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const replaceMatrixValue = (
matrix: number[][],
rowIndex: number,
columnIndex: number,
value: number
): void => {
if (
matrix[rowIndex] === undefined ||
matrix[rowIndex][columnIndex] === undefined
) {
throw new Error("Fora do intervalo da matriz");
}

matrix[rowIndex][columnIndex] = value;
};

// O(1)
10 changes: 10 additions & 0 deletions modulo6/complexidade-de-algoritmos/exercicio4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function verifyIfExistRepeatedNumbers(listOfNumbers: number[]): boolean {
for (let i = 0; i < listOfNumbers.length; i++) {
if (listOfNumbers.indexOf(listOfNumbers[i]) !== i) {
return true;
}
}
return false;
}

// O(n²)
1 change: 1 addition & 0 deletions modulo6/complexidade-de-algoritmos/exercicio5.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// 3 -> 1 = 2 -> 4, da maior eficiência para a menor perfomace
Loading