Skip to content

Instantly share code, notes, and snippets.

View ahmet-cetinkaya's full-sized avatar
🏠
Working from home

Ahmet Çetinkaya ahmet-cetinkaya

🏠
Working from home
View GitHub Profile
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml.Linq;
namespace saveAsXml
{
public partial class Form1 : Form
@ahmet-cetinkaya
ahmet-cetinkaya / MeanAndVarianceFunc.js
Created November 24, 2020 10:08
Find the mean, variance, and standard deviation in PERT
const meanAndVariance = (a, m, b) => ({"Mean": (a + 4 * m + b) / 6, "Standard Deviation": (b - a) / 6, "Variance": ((b - a) / 6) ** 2});
@ahmet-cetinkaya
ahmet-cetinkaya / removeDuplicates.js
Created November 24, 2020 14:40
LeetCode Solution 1047. Remove All Adjacent Duplicates In String
const removeDuplicates = (S) => S.match(/(.)\1/g) ? removeDuplicates(S.replace(/(.)\1/g, '')) : S;
@ahmet-cetinkaya
ahmet-cetinkaya / fibonacci.cpp
Created November 27, 2020 09:46
C++ Fibonacci Recursive Functions
#include<iostream>
using namespace std;
// @params a is first number.
// @params b is second number.
// @params c is the upper limit of numbers.
int fobi(int a, int b, int c) {
int next = a + b;
if (next > c) return 0;
cout << next << " ";
@ahmet-cetinkaya
ahmet-cetinkaya / bubbleSort.cpp
Last active December 29, 2020 10:51
Sort algorithms - Bubble Sort
#include<iostream>
using namespace std;
main()
{
int numbers[5] = { 10,1,53,5,8 };
int length = sizeof(numbers) / sizeof(numbers[0]);
for (int i = 0; i < length; ++i)
@ahmet-cetinkaya
ahmet-cetinkaya / selectionSort.cpp
Last active December 29, 2020 10:51
Sort algorithms - Selection Sort
#include<iostream>
using namespace std;
main()
{
int numbers[5] = { 10,1,53,5,8 };
int length = sizeof(numbers) / sizeof(numbers[0]);
for (int i = 0; i < length; ++i) {
@ahmet-cetinkaya
ahmet-cetinkaya / insertionSort.cpp
Last active December 29, 2020 10:51
Sort algorithms - Insertion Sort
#include<iostream>
using namespace std;
main()
{
int numbers[5] = { 10,1,53,5,8 };
int length = sizeof(numbers) / sizeof(numbers[0]);
for (int i = 1; i < length; ++i) {
int key = numbers[i];
@ahmet-cetinkaya
ahmet-cetinkaya / firstBadVersion.js
Created December 29, 2020 19:24
LeetCode Solution 278. First Bad Version
const solution = (isBadVersion) => (n) => {
let left = 1,
right = n;
while (left < right) {
const middle = Math.floor(left + (right - left) / 2);
if (isBadVersion(middle)) right = middle;
else left = middle + 1;
}
return left;
};
@ahmet-cetinkaya
ahmet-cetinkaya / jewelsAndStones.js
Last active December 30, 2020 18:04
LeetCode Solutions - 771. Jewels and Stones
const numJewelsInStones = (J, S) => {
let c = 0;
for (let i = 0; i < S.length; ++i) if (J.indexOf(S[i]) > -1) ++c;
return c;
};
@ahmet-cetinkaya
ahmet-cetinkaya / ransomNote.js
Created December 31, 2020 17:02
LeetCode Solutions - 383. Ransom Note
const canConstruct = (ransomNote, magazine) => {
const dicMap = new Map();
for (const c of magazine) dicMap.set(c, ~~dicMap.get(c) + 1);
for (const c of ransomNote) {
if (!dicMap.get(c)) return false;
dicMap.set(c, ~~dicMap.get(c) - 1);
}
return true;
};