Category Archives: LeetCode Solutions

Median of Two Sorted Arrays -LeetCode

There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)   ”’ Created on Jun 23, 2017 @author: asharda ”’ import numpy as … Continue reading

Posted in LeetCode Solutions, Uncategorized | Leave a comment

Reverse an Integer -LeetCode

import java.util.ArrayList; import java.util.List; import org.testng.annotations.Test; /** * @author asharda * */ public class TestReverseInteger { @Test public void testReverseInteger() { int num=123; int div=num; int rem=0; List<Integer> list=new ArrayList<Integer>(); while(div>100) { div=num/10; rem=num%10; list.add(rem); } list.add(div%10); list.add(div/10); Integer [] … Continue reading

Posted in Uncategorized, Java, LeetCode Solutions | Leave a comment

Single Element in a Sorted Array

/** * Find Single Non Duplicate Element in Array. * @author asharda * */ public class Solution { public static void main(String[] args) { int []arr={3,4,5,3,4,5,6}; System.out.println(“Result is “+singleNonDuplicate(arr)); } /** * Find single Non Duplicate * @param nums * … Continue reading

Posted in Java, LeetCode Solutions | Leave a comment

Divide function

package tests; import org.testng.annotations.Test; /** * Divide without standard divison and using add. * @author asharda * */ public class DivisonTest { public int divide(int dividend,int divisor) throws Exception { int count=0; int temp=divisor; if((divisor ==0) && (dividend!=0)) { throw new … Continue reading

Posted in Java, LeetCode Solutions, Uncategorized | Leave a comment