”’

Created on Jun 18, 2018

Linear Search in Python

@author: asharda

”’

def linear(arr,num):

for i in arr:

if(i==num):

return True

return False

arr=[10,7,12,5]

print(linear(arr, 8))

”’

Created on Jun 18, 2018

Linear Search in Python

@author: asharda

”’

def linear(arr,num):

for i in arr:

if(i==num):

return True

return False

arr=[10,7,12,5]

print(linear(arr, 8))

Advertisements

Posted in Data Structures, Python, Uncategorized
Leave a comment

”’

Created on Jun 15, 2018

@author: asharda

”’

def factorial(num):

if (num==1):

return 1;

else:

return factorial(num-1)*num;

print(factorial(5))

Posted in Uncategorized
Leave a comment

List<Integer> list = Arrays.stream(nums).boxed().collect(Collectors.toList()).stream().distinct().collect(Collectors.toList());

where nums is an int []

list.stream().mapToInt(i->i).toArray();

which returns int[]

Posted in Uncategorized
Leave a comment

https://leetcode.com/problems/divide-two-integers/description/

package src.test.java.examples;package src.test.java.examples;

public class Dividend {

public int divide(int dividend, int divisor) { int count = 0; boolean flag = false; if (dividend < 0 && divisor > 0) { flag = true; }

else if (dividend > 0 && divisor < 0) { flag = true; }

else if (dividend < 0 && divisor < 0) { flag = false; } if (dividend == -2147483648) { dividend = -2147483647; } dividend = Math.abs(dividend); divisor = Math.abs(divisor); while (dividend >= divisor) { dividend = dividend – divisor; count++; }

if (flag) { count = count * -1; }

return count; }

public static void main(String[] args) {

Dividend d = new Dividend(); System.out.println(d.divide(-2147483648, -1)); }

}

package src.test.java.examples;

/** * @author asharda * */

interface MyNumbers{ boolean test(int a,int b);}public class Lambda {

/** * @param args */ public static void main(String[] args) {

MyNumbers num; num=(a,b) -> { if(a%b ==0) { return true; } else { return false; } }; System.out.println(num.test(10, 2)); }

}

Posted in Uncategorized
Leave a comment