class Solution { public: Solution(int capacity){ cap = capacity; } int get(int key) { auto it = m.find(key); if (it == m.end()) return -1; l.splice(l.begin(), l, it->second); return it->second->second; } void set(int key, int value){ auto it = m.find(key); if...
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums1 int整型vector * @param nums2 int整型vector * @return int整型vector */ vector<int> intersection(vector<int>& nums1, vector<int>& nums2) { vector<int> tmp; sor...
class Solution { public: int Fibonacci(int n) { if(n==0) return 0; if(n==1||n==2) return 1; int i,a=1,b=1,result; for(i=3;i<=n;i++) { result=a+b; a=b; b=result; } return result; } };查看原帖点赞 评论相关...
class Solution { public:vector<vector<int> > rotateMatrix(vector<vector<int> > mat, int n){ int i;for(i = 0; i < n; i++){ for (int j = 0; j < i; j++){ swap(mat[i][j], mat[j][i]); //将行列进行互换 } } /*对每行的元素进行翻转*/ for (int m = 0; m <...
public class Solution{ public static void main(String[] args){ int[] nums = {5,4,3,2,1}; int[] temp = new int[nums.length]; MergeSort(nums, temp, 0, 4); for(int i=0; i<nums.length; i++) { System.out.print(nums[i] + ","); } System.out.println(); ListNode head ...
chinese dance class chinese day chinese dialogue teac chinese dish chinese divination chinese educational m chinese elder flower chinese electric capi chinese electronic co chinese entry chinese eunuch chinese even cabbage chinese exclusion act chinese finance socie chinese gall chinese gift chinese ginseng ...
class Solution { public: string removeDuplicateLetters(string s) { vector<int> vis(26), num(26); for (char ch : s) { num[ch - 'a']++; // 记录每一个字符的数量。 } string stk; for (char ch : s) { if (!vis[ch - 'a']) { // 如果栈中已经存在这个元素,那么无论如何也不...
//recursiveclass Solution1 {public:vector<int> inorderTraversal(TreeNode* root) {vector<int> ret;if(root==NULL)return ret;inorderHelper(ret,root);return ret;}private:void inorderHelper(vector<int>& ret,TreeNode* root){if(root==NULL)return;inorderHelper(ret,root->left);ret.push_back(...
#include <bits/stdc++.h>using namespace std;class Solution{public:void setZeroes(vector<vector<int>> &matrix){int i = matrix.size();int j = matrix[0].size();vector<int> hang(i);vector<int> lie(j);for (int m = 0; m < i; m++){for (int n = 0; n < j; n++){if (!
class of assets class of vessel class one medical cer class operators class selection class zhang wang class-acquainted classes of fits classful address classic books for qua classic bottle aged c classic car club of h classic controls classic des algorithm classic gourmet garde classic greece classi...