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
public class MoveZeros { | |
public void moveZeroes(int[] nums) { | |
int i = 0; | |
int j = 0; | |
while(i < nums.length && j < nums.length) { | |
if(nums[i] != 0) { | |
i++; | |
} else if(j <= i || nums[j] == 0) { | |
j++; | |
} 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.util.ArrayList; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.concurrent.ThreadLocalRandom; | |
public class LongestDuplicateSubstring { | |
private static final int PRIME = java.math.BigInteger.probablePrime(15, ThreadLocalRandom.current()).intValue(); | |
public String longestDupSubstring(String S) { |
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
public class HammingDistance { | |
public int hammingDistance(int x, int y) { | |
int res = x ^ y; | |
int count = 0; | |
while (res > 0) { | |
res = res & (res - 1); | |
count++; | |
} | |
return count; | |
} |
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
class MiddleOfLinkedList { | |
public ListNode middleNode(ListNode head) { | |
ListNode slow = head; | |
ListNode fast = head; | |
while (fast != null && fast.next != null) { | |
slow = slow.next; | |
fast = fast.next.next; | |
} | |
return slow; | |
} |
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 ballerina/http; | |
service websocket on new http:Listener(15300) { | |
resource function onText(http:WebSocketCaller caller, string text, | |
boolean finalFrame) { | |
checkpanic caller->pushText(text); | |
} | |
} |
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 json, os | |
import os | |
import time | |
import urllib | |
import urllib2 | |
from os.path import expanduser | |
from datetime import datetime | |
home_site = "http://bing.com" | |
weekly_wallpapers_url = home_site + "/HPImageArchive.aspx?format=js&idx=0&n=8&mkt=en-US" |
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 ballerina/http; | |
import ballerina/io; | |
listener http:Listener ep = new (9090); | |
service wsService = @http:WebSocketServiceConfig {} service { | |
resource function onText(http:WebSocketCaller wsEp, string text) { | |
io:println("Sever Received: " + text); | |
} | |
resource function onClose(http:WebSocketCaller wsEp, int statusCode, string reason) { | |
io:println("Connection closed"); |
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; | |
public class MatrixMultiplicationStrassen { | |
public static void main(String[] args) { | |
/*int[][] A = new int[][]{{1, 3}, {7, 5}}; | |
int[][] B = new int[][]{{6, 8}, {4, 2}};*/ | |
int[][] A = new int[][]{{13, -3, -25, 20}, {-3, -16, -23, 18}, {20, -7, 12, -5}, {-22, 15, -4, 7}}; | |
int[][] B = new int[][]{{13, 10, 11, 12}, {13, 14, -23, 18}, {20, -7, 12, -11}, {-12, -13, -14, 7}}; | |
System.out.println(Arrays.deepToString( |
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; | |
public class MatrixMultiplicationRecursive { | |
public static void main(String[] args) { | |
int[][] A = new int[][]{{13, -3, -25, 20}, {-3, -16, -23, 18}, {20, -7, 12, -5}, {-22, 15, -4, 7}}; | |
int[][] B = new int[][]{{13, 10, 11, 12}, {13, 14, -23, 18}, {20, -7, 12, -11}, {-12, -13, -14, 7}}; | |
System.out.println(Arrays.deepToString( | |
multiply(A, B, 0, 0, 0, 0, A.length) | |
)); |
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 ballerina/http; | |
import ballerina/io; | |
import ballerina/log; | |
public function main() { | |
http:WebSocketClient wsClientEp = new("ws://localhost:9090/ws/xyz/Mawanella?age=26", | |
config = {callbackService: ClientService, customHeaders:{"X-name":"Riyafa"}, subProtocols:["xml"]}); | |
var err = wsClientEp->pushText("hello"); | |
if (err is error) { | |
log:printError("Error in sending text", err = err); |