This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ss |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public List<List<Integer>> threeSum(int[] nums) { | |
Arrays.sort(nums); | |
List<List<Integer>> R = new ArrayList<List<Integer>>(); | |
int N = nums.length; | |
for(int i=0; i<N; i++){ | |
int j=0, k=N-1; | |
while(j>=0 && j<i && k>i && k<N) { | |
int sum3 = nums[i]+nums[j]+nums[k]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public int removeDuplicates(int[] A) { | |
if(A.length == 1){ | |
return 1; | |
} | |
int duplicates = 0, local_duplicates = 1; | |
for(int i = 0 ; i < A.length - 1;){ | |
if(A[i] == A[i + 1] && i < (A.length - duplicates)){ | |
local_duplicates++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public List<Integer> findMinHeightTrees(int n, int[][] edges) { | |
if(n==1) { | |
List<Integer> x = new ArrayList<Integer>(); | |
x.add(0); | |
return x; | |
} | |
List<List<Integer>> g = new ArrayList<List<Integer>>(n); | |
for(int i=0; i<n; i++){ | |
g.add(new ArrayList<Integer>()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for a binary tree node. | |
* struct TreeNode { | |
* int val; | |
* TreeNode *left; | |
* TreeNode *right; | |
* TreeNode(int x) : val(x), left(NULL), right(NULL) {} | |
* }; | |
*/ | |
class Solution { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#hello han | |
Problem 2: Write a function - sub count - that takes two arguments, a | |
string (s) and a substring (sub) , and returns the number of times sub | |
occurs in s. | |
For example: | |
x=‘you say hello and I say hello and they all say hello’ | |
print(subcount(x,’hello’)) should print 3 | |
print(subcount(x,’goodbye’)) should print 0 | |
(Note: There is a python string function count that does the same |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define _ ios_base::sync_with_stdio(0);cin.tie(0); | |
using namespace std; | |
#define PI acos(-1) | |
#define sqr(x) ((x) * (x)) | |
#define PB push_back | |
#define MP make_pair | |
#define F first |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.math.BigInteger; | |
import java.io.*; | |
import java.util.*; | |
/* | |
* Main.java | |
* java program model for www.programming-challenges.com | |
*/ | |
class Main implements Runnable { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define _ ios_base::sync_with_stdio(0);cin.tie(0); | |
using namespace std; | |
#define PI acos(-1) | |
#define sqr(x) ((x) * (x)) | |
#define PB push_back | |
#define MP make_pair | |
#define F first |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define _ ios_base::sync_with_stdio(0);cin.tie(0); | |
using namespace std; | |
#define PI acos(-1) | |
#define sqr(x) ((x) * (x)) | |
#define PB push_back | |
#define MP make_pair | |
#define F first |
NewerOlder