Skip to content

Instantly share code, notes, and snippets.

View pranuthi9's full-sized avatar

Pranuthi Mangu pranuthi9

View GitHub Profile
@pranuthi9
pranuthi9 / ClimbingStairs.java
Created July 23, 2014 20:24
Leetcode - ClimbingStairs
public class Solution {
public int climbStairs(int n) {
if (n < 2)
return n;
int[] numOnes = new int[n];
int[] numTwos = new int[n];
numOnes[0] = 1;
numTwos[0] = 0;
int[] dp = new int[n];
@pranuthi9
pranuthi9 / AtoI.java
Created July 21, 2014 21:48
atoi - leetcode
public class Solution {
public int atoi(String str) {
str = str.trim();
int len = str.length();
char[] s = str.toCharArray();
if (len == 0) return 0;
int i = 0;
boolean isNeg = false, invalid = false;
if (s[0] == '-') {
isNeg = true;
@pranuthi9
pranuthi9 / CountingSort.java
Created July 21, 2014 21:00
CountingSort - Leetcode
public class CountingSort {
public void sortColors(int[] A) {
int len = A.length;
if (len < 2) return;
int zeros = 0, ones = 0, twos = 0, i = 0;
for (i = 0; i < len; i++) {
if (A[i] == 0)
zeros++;
else if (A[i] == 1)
ones++;
@pranuthi9
pranuthi9 / TwoSum.java
Created July 21, 2014 20:45
TwoSum - LeetCode
public class Solution {
public int[] twoSum(int[] numbers, int target) {
int len = numbers.length;
int[] result = new int[2];
HashMap<Integer, Integer> map = new HashMap<Integer,Integer>();
result[0] = result[1] = -1;
if (len < 2) return result;
int num = 0;
for (int i = 0; i < len; i++) {
num = numbers[i];
@pranuthi9
pranuthi9 / NestedParantheses
Last active August 29, 2015 14:03
Codility - Lesson 5 - Nested Parantheses
// you can also use imports, for example:
// import java.math.*;
// you can use System.out.println for debugging purposes, e.g.
// System.out.println("this is a debug message");
// Time Complexity: O(N)
// Space Complexity: O(1)
class Solution {
public int solution(String S) {
@pranuthi9
pranuthi9 / MatchingBrackets
Created July 15, 2014 03:26
Codility - Lesson 5 - Brackets
import java.util.Stack;
class Solution {
public int solution(String S) {
// write your code in Java SE 8
int len = S.length();
if (len == 0)
return 1;
if (len == 1)
return 0;
char ch;
@pranuthi9
pranuthi9 / PrefixSet
Last active August 29, 2015 14:03
Codility - Challenges - Prefix Set
// you can also use imports, for example:
// import java.math.*;
// you can use System.out.println for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len = A.length;
@pranuthi9
pranuthi9 / Triangle.java
Created July 12, 2014 20:59
Codility - Lesson 4 - Triangle
// you can also use imports, for example:
// import java.math.*;
// you can use System.out.println for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Arrays;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len = A.length;
@pranuthi9
pranuthi9 / MaxProductOfThree
Created July 12, 2014 20:01
Codility - Lesson 4 - Max Product of Three
import java.util.Arrays;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
Arrays.sort(A);
int len = A.length;
int right = A[len-1]*A[len-2]*A[len-3];
int left = A[0]*A[1]*A[len-1];
return right > left ? right : left;
}
@pranuthi9
pranuthi9 / Disinct
Created July 12, 2014 19:40
Codility - Lesson 4 - Distinct
// you can also use imports, for example:
// import java.math.*;
// you can use System.out.println for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.HashSet;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
int len = A.length;