Skip to content

Instantly share code, notes, and snippets.

View pitsanujiw's full-sized avatar

Pitsanu L. pitsanujiw

View GitHub Profile
/**
*
* @param {string} str
* @returns {string}
*/
function longestPalindrome(str) {
if (!str?.length) {
return "";
}
function reverse(nums) {
if (!nums) return;
let newList = [];
for (let i = nums.length -1; i >= 0; i--) {
newList.push(nums[i]);
}
return newList;
}
function isAnagram(s, t) {
let ss =s.split('').sort();
let tt = t.split('').sort();
if (s.length != t.length) return false;
for (let i = 0; i < s.length; i++) {
if (ss[i] != tt[i]) {
return false;
}
}
return true;
public class Solution {
public void MoveZeroes(int[] nums) {
int indexSwap = 0;
for (int i = 0; i < nums.Length; i++)
{
if (nums[i] != 0)
{
if (i != indexSwap)
{
nums[indexSwap] = nums[i];
public class Solution {
public int[] TwoSum(int[] nums, int target) {
for (int i = 0; i < nums.Length; i++) {
for (int j = i + 1; j < nums.Length; j++) {
if (nums[j] == target - nums[i]) {
return new int[] { i, j };
}
}
}
return new int[0];
function removeDuplicates(nums: number[]): number[] {
if (nums.length === 0) return [];
let i=0;
nums.sort();
for (let j =1; j < nums.length; j++) {
if (nums[j] != nums[i]) {
i++;
nums[i] = nums[j];
}
}
@pitsanujiw
pitsanujiw / rotate.ts
Last active January 11, 2021 09:18
Rotate Matrix (Transpose)
function rotate(matrix: number[][]) {
let n = matrix.length;
// transpose matrix
for (let i = 0; i < n; i++) {
for (let j = i; j < n; j++) {
let tmp = matrix[j][i];
matrix[j][i] = matrix[i][j];
matrix[i][j] = tmp;
console.log(tmp,matrix[j][i]);
}
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}
@pitsanujiw
pitsanujiw / wallet-signature-bruteforce.go
Created June 9, 2019 14:05
Finding the valid order of a secret message
package main
import (
"github.com/gitchander/permutation"
"encoding/hex"
"crypto/sha1"
"crypto/hmac"
"strings"
"fmt"
"os"
import binascii
import hashlib
import hmac
def genSigninRequestOtpSignature(signinType, deviceId, timestamp):
"""
url: "https://mobile-api-gateway.truemoney.com/mobile-api-gateway/api/v1/login/otp/"
headers:
username => str (ex: "09XXXXXXXX")
password => str (ex: "da39a3ee5e6b4b0d3255bfef95601890afd80709")