头像

小王子和他的狐狸


访客:3782

离线:8个月前



由于py数字理论可以无限大,所以直接读取算出答案即可

a = input()
b = input()
print(eval(str(a)) + eval(str(b)))



class Solution:
    def removeDuplicateLetters(self, s: str) -> str:

        for i in sorted(set(s)):
            suff = s[s.index(i):]
            if set(suff) == set(s):
                return i + self.removeDuplicateLetters(suff.replace(i, ''))
        if s == '':
            return s
a = Solution()
s = input()
s = a.removeDuplicateLetters(s)
print(s[0])



import java.util.Iterator;
import java.util.Scanner;

class Graph{
    private final int V;//顶点数目
    private int E;//边的数目
    private Bag<Integer>[] adj;//邻接表

    public Graph(int V){
        this.V = V;
        this.E = 0;
        adj = (Bag<Integer>[]) new Bag[V];//创建邻接表
        for(int v = 0;v<V;v++){
            adj[v] = new Bag<Integer>();
        }
    }
    public int V(){return V;}
    public int E(){return E;}
    public void addEdge(int v,int w){
        adj[v].add(w);
        adj[w].add(v);
        E++;
    }
    public Iterable<Integer> adj(int v){ return adj[v];}
    public String toString(){
        String s = V + " vertices, " + E +" edges\n";
        for(int v=0;v<V;v++){
            s+=v+":";
            for(int w:this.adj(v))
                s+=w+" ";
            s+="\n";
        }
        return s;
    }
}
class Bag<Item> implements Iterable<Item> {
    //链表实现Bag
    private Node first;//链表首结点
    private class Node{
        Item item;
        Node next;
    }
    //和stack的push方法完全相同,在头部添加
    public void add(Item item){
        Node oldFirst = first;
        first = new Node();
        first.item = item;
        first.next = oldFirst;
    }
    @Override
    public Iterator<Item> iterator() {
        return new ListIterator();
    }

    private class ListIterator implements Iterator<Item>{
        private Node current = first;

        @Override
        public boolean hasNext() {
            return current!=null;
        }

        @Override
        public Item next() {
            Item item = current.item;
            current = current.next;
            return item;
        }
    }
}
public class demo{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Graph G = new Graph(4);//此处传入顶点数
        for(int i=0;i<6;i++){//此处传入边数 ,这里假设有六条边
            int a = in.nextInt();
            int b= in.nextInt();
            G.addEdge(a,b);
        }
        System.out.println(G.toString());
    }
}

这里使用邻接表数组来储存图,该图是无向图。




class Solution {
    public String longestPalindrome(String s) {
        if(s.length() == 0)
            return "";
        char[] c = s.toCharArray();
        int[] range = new int[2];
        for(int i = 0; i < s.length(); i ++){
            i = next(c,i,range);
        }
        return s.substring(range[0],range[1]+1);
    }

    int next(char[] c, int low, int[] range){
        int max = c.length - 1;
        int high = low;
        while(high < max && c[high+1] == c[low])
            high ++;
        int result = high;
        while(low > 0 && high < max && c[high+1] == c[low-1]){
            low --;
            high ++;
        }
        if((high - low) > (range[1]-range[0])){
            range[0] = low; range[1] = high;
        }
        return result;    
    }


}



新新新方法来了

class Solution {
    public boolean hasPath(char[][] matrix, String str) {
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[0].length; j++) {
                boolean res = this.dfs(matrix, i, j, str, 0);
                if(res) {
                    return res;
                }
            }
        }
        return false;
    }

    public boolean dfs(char[][] matrix, int i, int j, String str, int k) {
        // TODO Auto-generated method stub
        if (k >= str.length()) {
            return true;
        }
        if (  i < 0 || i >= matrix.length || j < 0 || j >= matrix[0].length||matrix[i][j] != str.charAt(k)) {
            return false;
        }
        char c = matrix[i][j];
        matrix[i][j] = '#';
        boolean res= dfs(matrix, i+1, j, str, k+1) ||
                dfs(matrix, i, j+1, str, k+1)||
                dfs(matrix, i-1, j, str, k+1)||
                dfs(matrix, i, j-1, str, k+1);
        matrix[i][j] = c;
        return res;

    }
}



排序 + py

class Solution:
    def findMin(self, nums):
        """
        :type nums: list
        :rtype: int
        """
        if len(nums) == 0:
            return -1

        return sorted(nums[:])[0]



import itertools
class Solution:
    def permutation(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """

        l= list(itertools.permutations(nums, len(nums))) 
        return list(set(l))

实在不会啊




class Solution(object):
    def findNumberAppearingOnce(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        for i in nums:
            if nums.count(i) == 1:
                return i
        return 0



java代码

class Solution {
    public char firstNotRepeatingChar(String s) {
        int len = s.length();
        for(int i=0;i<len;i++) {
            if(s.indexOf(s.charAt(i))==s.lastIndexOf(s.charAt(i))) {
                return s.charAt(i);
            }

        }
        return '#';             
    }
}




class Solution {
public:
    vector<int> printListReversingly(ListNode* head) {
        vector<int> res;
        head = reverse(head);
        while(head){
            res.push_back(head->val);
            head = head->next;
        }
        return res;
    }
    ListNode* reverse(ListNode *head){

        if(head==NULL||head->next==NULL){
            return head;
        }
        ListNode* temp = reverse(head->next);
        head->next->next = head;
        head->next = NULL;
        return temp;
    }
};