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 boolean isPalindrome(String str) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
str=str.toLowerCase(); | |
int start=0, end=str.length()-1; | |
while(start<=end) | |
{ | |
if(start<=end && outOfRange(str.charAt(start))) |
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 binary tree | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ | |
public 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
#include <algorithm> | |
class Solution { | |
public: | |
class Pair | |
{ | |
public: | |
int index; | |
int val; |
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 singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode(int x) : val(x), next(NULL) {} | |
* }; | |
*/ | |
class Solution { | |
public: |
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
class Solution { | |
public: | |
string convert(string s, int nRows) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
if(nRows<=1) return s; | |
int length=s.length(); | |
int numberItems=2*(nRows-1); | |
int zones=length/numberItems+(length%numberItems==0? 0: 1); |
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 boolean isMatch(String s, String p) { | |
if(s!="" && p=="") return false; | |
char [] sArray=s.toCharArray(); | |
int sLength=sArray.length; | |
char [] pArray=p.toCharArray(); | |
int pLength=pArray.length; | |
int i=0, j=0; | |
while(i<sLength && j<pLength){ |
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
class Solution { | |
public: | |
string longestCommonPrefix(vector<string> &strs) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
string result=""; | |
if(strs.size()==0) return result; | |
result=strs[0]; | |
for(int i=1; i<strs.size(); i++) | |
{ |
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
class Solution { | |
public: | |
string intToRoman(int num) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
string result=""; | |
if(num>=1000) result+=string(num/1000, 'M'); | |
num=num%1000; result+=stringHelper(num/100, "C", "D", "M"); | |
num=num%100; result+=stringHelper(num/10, "X", "L", "C"); | |
num=num%10; result+=stringHelper(num, "I", "V", "X"); |
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
class Solution { | |
public: | |
int romanToInt(string s) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
if(s.length()==0) return 0; | |
map<char, int> mp; | |
mp['M']=1000; | |
mp['D']=500; | |
mp['C']=100; |
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
class Solution { | |
public: | |
vector<vector<int> > threeSum(vector<int> &num) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
vector<vector< int > > result; | |
if(num.size()<3) return result; | |
sort(num.begin(), num.end()); | |
for(int i=0; i<=num.size()-3; i++) | |
{ |
OlderNewer