This file contains hidden or 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
class Solution { | |
public: | |
bool isValid(string s) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
if(s.length()==0) return true; | |
stack<char> st; | |
for(int i=0; i<s.length(); i++) | |
{ | |
if(s[i]=='(' || s[i]=='{' || s[i]=='[') |
This file contains hidden or 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
class Solution { | |
public: | |
int maxArea(vector<int> &height) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
int end=height.size()-1; | |
if(end<=0) return 0; | |
int start=0; | |
int maxWater=0; | |
while(start<end) |
This file contains hidden or 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
class Solution { | |
public: | |
bool isPalindrome(int x) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
if(x<0) return false; | |
int counter=1; | |
while(x/counter>=10) | |
{ | |
counter*=10; |
This file contains hidden or 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
class Solution { | |
public: | |
int atoi(const char *str) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
if(*str=='\0') return 0; | |
while(*str==' ') str++; | |
bool negative=false; | |
if(*str=='-') | |
{ |
This file contains hidden or 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 reverse(int x) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
if(x==0) return 0; | |
boolean negative=false; | |
if(x<0) { negative=true; x=-x; } | |
int result=0; | |
while(x!=0) | |
{ |
This file contains hidden or 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
class Solution { | |
public: | |
int lengthOfLongestSubstring(string s) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
int length=s.length(); | |
bool exist[256]={false}; | |
int start=0; | |
int maxL=0; | |
for(int i=0; i<length; i++) |
This file contains hidden or 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.io.*; | |
public static void main(String[] args) throws IOException { | |
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ | |
BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); | |
String s; | |
int numberOfLines=Integer.parseInt(in.readLine()); | |
for(int i=0; i<numberOfLines; i++) | |
{ | |
s=in.readLine(); | |
String []array=s.split(); |
This file contains hidden or 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 jump(int[] A) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
int length=A.length; | |
if(length==0) return 0; | |
int startPos=0; //the start position of the current jump | |
int max=0; //total max jump | |
int tempMax=0; | |
int jumpCounter=0; |
This file contains hidden or 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.util.*; | |
public class Solution { | |
public ArrayList<String> anagrams(String[] strs) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
ArrayList<String> result=new ArrayList<String>(); | |
if(strs.length==0) return result; | |
Hashtable<String, ArrayList<String>> table=new Hashtable<String, ArrayList<String>>(); | |
for(int i=0; i<strs.length; i++) | |
{ |
This file contains hidden or 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 double pow(double x, int n) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
if(n==0) return 1; | |
if(x==0) return 0; | |
if(n==1) return x; | |
if(n<0) | |
{ | |
n=-n; x=1/x; |