合并两个有序链表
摘要:方法一: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class
阅读全文
有效括号方法二
摘要:class Solution { // Hash table that takes care of the mappings. private HashMap<Character, Character> mappings; // Initialize hash map with mappings.
阅读全文
有效括号
摘要:class Solution {public: bool isValid(string s) { int flag=1; //标志位 int len=s.size(); if(len==0) { return true; } //判断输入是否为空 char str[len]; int top=0;
阅读全文
最长公共前缀
摘要:方法一 循环: class Solution {public: string longestCommonPrefix(vector<string>& strs) { if(strs.empty()) { return ""; } //注意为空的情况 string str1; //从vector中取
阅读全文
罗马数字转换成整数
摘要:方法一: class Solution {public: int romanToInt(string s) { int len=s.size(); map<string,int> number{ {"I",1}, {"V",5}, {"X",10}, {"L",50}, {"C",100}, {"D
阅读全文
回文数
摘要:方法一: class Solution {public: bool isPalindrome(int x) { if(x<0) return false; int count=0; //用来记录x的位数 int num; //每一位的数字 int y[10]; //声明一个数组用来存每一位的数字 w
阅读全文