¥ java leetcode ¥寻找两个有序数组的中位数
/*** 不使用递归的二分查找*title:commonBinarySearch*@param arr*@param key*@return 关键字位置*/public static int commonBinarySearch(int[] arr,int key){int low = 0;int high = arr.length - 1;int middle = 0; //定义middle if(key < arr[low] || key > arr[high] .
MongoDB按时间年月日查询数据
我用#CSDN#这个app发现了有技术含量的博客,小伙伴们求同去《MongoDB按时间年月日查询数据》, 一起来围观吧 https://blog.csdn.net/qq_27292113/article/details/96150302?utm_source=app
¥java leetcode¥ 最长回文子串 最优解法
动态规划 class Solution { public String longestPalindrome(String s) { int len = s.length(); // 特判 if (len < 2){ return s; } int maxLen = 1; int begin = 0; // 1. 状态定义 /...
¥ 8 字符串 ¥ 字符串转换整数 (atoi)
方法一:自动机思路字符串处理的题目往往涉及复杂的流程以及条件情况,如果直接上手写程序,一不小心就会写出极其臃肿的代码。因此,为了有条理地分析每个输入字符的处理方法,我们可以使用自动机这个概念:我们的程序在每个时刻有一个状态 s,每次从序列中输入一个字符 c,并根据字符 c 转移到下一个状态 s'。这样,我们只需要建立一个覆盖所有情况的从 s 与 c 映射到 s' 的表格即可解决题目中的问题。接下来编程部分就非常简单了:我们只需要把上面这个状态转换表抄进代码即可。另外自动机也
¥9 数字的位操作¥回文数
class Solution {public: bool isPalindrome(int x) { // 特殊情况: // 如上所述,当 x < 0 时,x 不是回文数。 // 同样地,如果数字的最后一位是 0,为了使该数字为回文, // 则其第一位数字也应该是 0 // 只有 0 满足这一属性 if (x < 0 || (x % 10 == 0 && x != 0)) .
¥10 动态规划与字符串匹配¥ 正则表达式匹配v
1.全匹配,而不是匹配字符串的一部分class Solution { public boolean isMatch(String s, String p) { int m = s.length(); int n = p.length(); boolean[][] f = new boolean[m + 1][n + 1]; f[0][0] = true; for (int i = 0; i <=..
¥11 双指针 ¥装水最多的容器
思路:https://leetcode-cn.com/problems/container-with-most-water/solution/sheng-zui-duo-shui-de-rong-qi-by-leetcode-solution/暴力解法class Solution { public int maxArea(int[] height) { int maxarea=0; int len=height.length; fo.
¥12 数字与字符串间转换 ¥整数转罗马数字
class Solution { public String intToRoman(int num) { String str =""; Map map=new HashMap(); map.put("1","I"); map.put("4","IV"); map.put("5","V"); map.put("9","IX"); map.put("10","X"); ma.
¥13 数字与字符串间转换 ¥ 罗马数字转整数
class Solution { public int romanToInt(String s) { int[] arr={1,5,10,50,100,500,1000}; //String[] symbols = {"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"}; char[] symbols = {'I','V','X','L','C','D','M'}; i.
¥14 字符串——公共前缀 ¥最长公共前缀
class Solution { public static String longestCommonPrefix(String[] strs) { String result = ""; int len = strs.length; if (len <= 0) return result; int minstringlen=strs[0].length();//所有字符串的最小length,初始化为第一个
¥15 头尾指针¥三数之和
https://leetcode-cn.com/problems/3sum/solution/san-shu-zhi-he-by-leetcode-solution/class Solution { public static List<List<Integer>> threeSum(int[] nums) {// int [] nums={-4,0,1,2,-1,-1,-4}; List list = new ArrayList();
¥17 递归回溯 ¥电话号码的字母组合
https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/solution/dian-hua-hao-ma-de-zi-mu-zu-he-by-leetcode-solutio/class Solution { public List<String> letterCombinations(String digits) { List<String> combinations =
¥19 链表的删除¥删除链表的倒数第N个节点
不使用哑结点100.00%99%/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this
¥20 哈希表与统计¥有效的括号
class Solution { public boolean isValid(String s) { Stack stack = new Stack(); // 创建堆栈对象 int len=s.length(); for (int i = 0; i < len; i++) { char c=s.charAt(i); switch (c) { case .
¥21 链表的合并¥合并两个有序链表
public ListNode mergeTwoLists5(ListNode l1, ListNode l2) { ListNode result = new ListNode(); ListNode l3 = result;//让L3劳动,最后返回result while (l1 != null && l2!= null) { if (l1.val < l2.val) { ...
今日推荐
周排行