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 { | |
static final int MAX = 46340; | |
public int sqrt(int x) { | |
int s = 1, e = x; | |
if(e>MAX) | |
e = MAX; |
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 trap(int A[], int n) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
int s = 0, e = n - 1; | |
int curl = 0, max = 0, sum = 0; | |
while (s < e) { | |
while (s < e && A[s] <= curl) { | |
sum += A[s]; |
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.Arrays; | |
public class GenFunc { | |
/** | |
* 求用不同面值的硬币组合出数值为sum的方案数,每种硬币可以用任意个 | |
* */ | |
public int genFunc(int[] coins, int sum) { | |
int[] state = new int[sum + 1]; | |
state[0] = 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
#include <iostream> | |
#include <vector> | |
using namespace std; | |
class Solution { | |
public: | |
void nextPermutation(vector<int> &num) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function |
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
#include <iostream> | |
#include <string> | |
#include <string.h> | |
#include <algorithm> | |
#include <vector> | |
using namespace std; | |
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
import java.util.ArrayList; | |
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
import java.util.ArrayList; | |
public class GenerateParenthesis { | |
public ArrayList<String> generateParenthesis(int n) { | |
ArrayList<String> results = new ArrayList<String>(); | |
gp(n, n, new StringBuilder(), results); | |
return results; | |
} |
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.Comparator; | |
import java.util.HashMap; | |
import java.util.TreeMap; | |
public class Test { | |
static class IntToRoman { | |
public int romanToInt(String s) { | |
int res = 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
//============================================================================ | |
// Name : Coding.cpp | |
// Author : Plex | |
// Version : 1.0 | |
// Copyright : Your copyright notice | |
// Description : Hello World in C++, Ansi-style | |
//============================================================================ | |
#include<iostream> | |
using namespace std; |
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
#include<stdio.h> | |
int count = 0; | |
void func(int sx, int sy, int ex, int ey){ | |
if(sx<ex) | |
func(sx+1, sy, ex, ey); | |
if(sy<ey) | |
func(sx, sy+1, ex, ey); | |
if(sx==ex && sy==ey) |