This file contains hidden or 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
import 'package:flutter/material.dart'; | |
extension ColorDegree on Color { | |
Color darken([int percent = 10]) { | |
assert(1 <= percent && percent <= 100); | |
var f = 1 - percent / 100; | |
return Color.fromARGB( | |
this.alpha, (this.red * f).round(), (this.green * f).round(), (this.blue * f).round()); | |
} |
This file contains hidden or 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
/// Finds the width of a text before rendering it. | |
Size findTextSize( | |
{required String text, | |
TextStyle style = textStyle, | |
required BuildContext context, | |
TextDirection textDirection = TextDirection.rtl}) { | |
final Size size = (TextPainter( | |
text: TextSpan(text: text, style: style), | |
maxLines: 5, | |
textScaleFactor: MediaQuery.of(context).textScaleFactor, |
This file contains hidden or 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
package datastructures.main; | |
import java.util.Stack; | |
public class Brackets { | |
public static void main(String[] args) { | |
boolean isValid = false; | |
String inputString = "[()]()()()"; | |
Stack<Character> myStack = new Stack<>(); | |
boolean valid = true; |
This file contains hidden or 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
// | |
// This is only a SKELETON file for the 'Linked List' exercise. It's been provided as a | |
// convenience to get you started writing code faster. | |
// | |
/// Supposing that the list has at least one item. | |
class Node { | |
constructor(value, previous, next) { | |
this.value = value; | |
this.previous = previous; |
This file contains hidden or 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
import java.util.*; | |
public class Dijkstra { | |
public static String findLowestNode(HashMap<String, Integer> costs, ArrayList<String> processedNodes) { | |
String lowestNode = null; | |
Integer lowestNodeVal = Integer.MAX_VALUE; | |
for (String node : costs.keySet()) { | |
if (lowestNodeVal > costs.get(node) && !processedNodes.contains(node)) { |
This file contains hidden or 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
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
public class QuickSort { | |
public static List<Integer> quickSort(List<Integer> array) { | |
if (array.size() < 2) { | |
return array; | |
} else { |
This file contains hidden or 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
import java.io.*; | |
import java.util.*; | |
public class problemSolving { | |
private static int getMajorityElement(int[] a) { | |
//Java's sort is a dual pivot quick sort which is basically O(nlog n) | |
Arrays.sort(a); | |
//We here set a counter to count the duplicated elements |
This file contains hidden or 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
import java.io.*; | |
import java.util.*; | |
public class problemSolving { | |
static int binarySearch(int[] a, int x, int left, int right) { | |
if (left > right) { | |
return -1; | |
} | |
int middle = left + ((right - left) / 2); |
This file contains hidden or 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
import java.util.Arrays; | |
import java.util.Random; | |
public class problemSolving { | |
static void RandomizedQuickSort(int[] array, int l, int r) { | |
//We first check if the left-most element index is greater than right-most element index | |
//This is considered as a base case to exit from infinite recursive calls | |
while (l < r) { |
This file contains hidden or 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
import java.util.Arrays; | |
import java.util.Random; | |
public class problemSolving { | |
static void RandomizedQuickSort(int[] array, int l, int r) { | |
//We first check if the left-most element index is greater than right-most element index | |
//This is considered as a base case to exit from infinite recursive calls | |
if (l >= r) { |
NewerOlder