Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added #442/java/hashmap/.DS_Store
Binary file not shown.
69 changes: 69 additions & 0 deletions #442/java/hashmap/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.jagjit.Hactoberfest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
* https://leetcode.com/problems/find-all-duplicates-in-an-array/
* runtime beats 9.32% of Java submissions
* memory usage beats 36.11% of Java submissions
*/


public class FindDuplicates {

// function that return the value
private static List<Integer> findDuplicates(int[] nums) {

List<Integer> result = new ArrayList<Integer>();

// initialising the hashmap
int count = 0;
Map<Integer, Integer> map = new HashMap<Integer, Integer>();

//iterates through every element
for (int i = 0; i < nums.length; i++) {

//if map contains duplicate value then add to result list
if (map.containsKey(nums[i])) {
result.add(nums[i]);
}
//putting the value in the map
map.put(nums[i], count++);
}

//return the final list
return result;

}

public static void main(String[] args) {

// allocating memory for 5 integers.
int[] nums = new int[8];

// initialize the first elements of the array
nums[0] = 4;
nums[1] = 3;
nums[2] = 2;
nums[3] = 7;
nums[4] = 8;
nums[5] = 2;
nums[6] = 3;
nums[7] = 1;

List<Integer> result = findDuplicates(nums);

for (Integer i : result) {

//print the value of duplicates value
System.out.print(i + " ");

}

}

}
24 changes: 24 additions & 0 deletions #70/java/dynamic_programming/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.jagjit.Hactoberfest;

/**
* https://leetcode.com/problems/climbing-stairs/ Runtime: 0 ms, faster than
* 100.00% of Java online submissions for Climbing Stairs. Memory Usage: 33.2
* MB, less than 5.26% of Java online submissions for Climbing Stairs.
*/
public class Solution {

// below the function which returns count
public int climbStairs(int n) {
int[] dp = new int[n];
if (n < 2) {
return 1;
}
dp[0] = 1;
dp[1] = 2;
for (int i = 2; i < n; i++) {
dp[i] = dp[i - 1] + dp[i - 2];
}
return dp[n - 1];
}

}