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 threeSumClosest(vector<int> &num, int target) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
sort(num.begin(), num.end()); | |
int result=num[0]+num[1]+num.back(); | |
for(int i=0; i<num.size(); i++) | |
{ | |
int j=i+1, k=num.size()-1; |
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 static ArrayList<String> letterCombinations(String digits) { | |
if(digits==null) return null; | |
ArrayList<String> result=new ArrayList<String>(); | |
if(digits.length()==0) | |
{ | |
result.add(""); | |
return result; | |
} | |
char [][] maps=new char[10][4]; |
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
/** | |
* Definition for singly-linked list. | |
* public class ListNode { | |
* int val; | |
* ListNode next; | |
* ListNode(int x) { | |
* val = x; | |
* next = null; | |
* } | |
* } |
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 boolean isValid(String s) { | |
int length=s.length(); | |
char [] array=s.toCharArray(); | |
if(length==0) return true; | |
Stack<Character> stack=new Stack<Character>(); | |
for(int i=0; i<length; i++) | |
{ | |
if(array[i]=='(' || array[i]=='{' || array[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 ArrayList<String> generateParenthesis(int n) { | |
ArrayList<String> result=new ArrayList<String>(); | |
char [] array=new char[2*n]; | |
generate(result, n, n, array, 0); | |
return result; | |
} | |
void generate(ArrayList<String> result, int left, int right, char [] array, int num) | |
{ | |
if(left==0 && right==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
/** | |
* Definition for singly-linked list. | |
* public class ListNode { | |
* int val; | |
* ListNode next; | |
* ListNode(int x) { | |
* val = x; | |
* next = null; | |
* } | |
* } |
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
/** | |
* Definition for singly-linked list. | |
* public class ListNode { | |
* int val; | |
* ListNode next; | |
* ListNode(int x) { | |
* val = x; | |
* next = null; | |
* } | |
* } |
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
/** | |
* Definition for singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode(int x) : val(x), next(NULL) {} | |
* }; | |
*/ | |
class Solution { | |
public: |
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 maxProfit(int[] prices) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
if(prices.length==0) return 0; | |
int profit=0; | |
for(int i=1; i<prices.length; i++) | |
{ | |
if(prices[i]>prices[i-1]) | |
{ |
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 maxProfit(int[] prices) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
if(prices.length==0) return 0; | |
int min=prices[0], max=prices[0]; | |
int profit=0; | |
for(int i=1; i<prices.length; i++) | |
{ | |
if(prices[i]>max) |