Skip to content

Instantly share code, notes, and snippets.

View ozkansari's full-sized avatar
🏠
Working from home

Ozkan Sari ozkansari

🏠
Working from home
View GitHub Profile
@ozkansari
ozkansari / LastStoneWeight.java
Last active April 12, 2020 13:36
We have a collection of stones, each stone has a positive integer weight. Each turn, we choose the two heaviest stones ( x and y) and smash them together. As a result, both destroyed but a new stone added having the absolute wieght difference ( |x-y|) if it is not equal to zero. https://leetcode.com/explore/challenge/card/30-day-leetcoding-chall…
package leetcode.laststone;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* We have a collection of stones, each stone has a positive integer weight.
@ozkansari
ozkansari / BinaryTreeDiameterCalculatorWithStack.java
Last active April 11, 2020 15:28
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may not pass through the root. https://leetcode.com/explore/challenge/card/30-day-leetcoding-challenge/529/week-2/3293/
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
@ozkansari
ozkansari / MinStack.java
Last active April 11, 2020 12:02
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/529/week-2/3292/
/**
* Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
* Your MinStack object will be instantiated and called as such:
*
* > MinStack obj = new MinStack();
* > obj.push(x);
* > obj.pop();
* > int param_3 = obj.top();
* > int param_4 = obj.getMin();
@ozkansari
ozkansari / BackspaceStringCompareWithStack.java
Created April 10, 2020 14:46
Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.https://leetcode.com/explore/challenge/card/30-day-leetcoding-challenge/529/week-2/3291/
import java.util.*;
class BackspaceStringCompareWithStack {
/**
* @param S lower case letters with backspace # E.g. ab##
* @param T lower case chars with backspace # E.g. #a#c
*
* @return S contentEquals T
*/
@ozkansari
ozkansari / BackspaceStringCompareInterpreter.java
Last active April 10, 2020 06:54
Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.https://leetcode.com/explore/challenge/card/30-day-leetcoding-challenge/529/week-2/3291/
class BackspaceStringCompareInterpreter {
/**
* Given two strings S and T, return if they are equal when both are typed into empty text editors.
*
* Performance: O(n) time, O(n) space
*
* @param S lower case letters with backspace # E.g. ab##
* @param T lower case chars with backspace # E.g. #a#c
@ozkansari
ozkansari / PrintPairsThatGivesASum.java
Created April 1, 2019 21:14
Prints all combinations of 2 numbers in the list that sum to s
/*--
Write a function, that given a list (or array) of integers and an integer s,
prints all combinations of 2 numbers in the list that sum to s.
For the list 1, 2, 3 and sum = 4, your function could print:
1 + 3 = 4
3 + 1 = 4
*/
import java.util.*;
@ozkansari
ozkansari / EncryptSample.java
Created March 27, 2019 15:21
PIN Block Creation
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class EncryptSample {
private static final String KEY = "AB1C11111111111AAAAAAADDDDD11111";
private static final int PIN_LENGTH = 6;
public static void main(String[] args) throws Exception {
@ozkansari
ozkansari / FileWriteExample.java
Last active November 17, 2018 06:20
File Write Example Java
public class FileWriteExample {
public static void main(String[] args) {
writeToFile(".\\config\\Ogrenciler_Program.txt", "mesaj 1", "mesaj 2");
}
private static void writeToFile(String filePath, String [] messages) throws FileNotFoundException {
File ciktiDosyasi = new File();
PrintWriter dosyaYazici = new PrintWriter(ciktiDosyasi);
for (String m : messages) {
dosyaYazici.println(o);
@ozkansari
ozkansari / MedipolNYP2017BaharOdev2.java
Last active March 5, 2017 00:23
Medipol NYP 2017 Bahar 2. Odev
public class MedipolNYP2017BaharOdev2 {
public static void main(String[] args) {
int[] ogrenciSinavSonuclari =
{ 65, 80, 80, 20, 65, 65, 15, 80, 70 };
// 101 farkli not olabilir
int[] notlarIstatistik = new int[101];
// hesapla -
// Bu kismi siz yapacaksiniz
@ozkansari
ozkansari / AddMultiply.java
Last active August 29, 2015 14:02
TopCoder: SRM 625 Div2 Round 1
/**
* TopCoder: SRM 625 Div2 Round 1
*
* http://community.topcoder.com/stat?c=problem_statement&pm=13231&rd=15858&rm=322742&cr=20029384
*
* You are given an int y. We are looking for any int[] x that satisfies the following constraints:
* - No x[i] can be equal to 0 or 1.
* - Each x[i] must be between -1000 and 1000, inclusive.
* - ( x[0] * x[1] ) + x[2] = y
* - x has exactly three elements