![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode练习
赤瞳寓言
加油!
展开
-
Problem6:ZigZag Conversion
看了别人的,然后自己重新写了一遍理解了,但是目前没有再想到更好的解决办法。题目:The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font转载 2017-12-08 15:43:31 · 155 阅读 · 0 评论 -
Problem45.Jump Game II
问题:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is...原创 2018-07-06 22:08:13 · 133 阅读 · 0 评论 -
Problem4: Median of Two Sorted Arrays
刚开始做,还以为与前面一样不难,结果踩雷了,用的最原始的方法,先合并了两个有序数组为1个有序数组,然后返回中间值,后面学到优化的算法再回来补充!用最原始的方法,一开始会出现访问越界的情况,是因为没有考虑清楚如果有一个数组为空时的情况!特此记录一下,采用一般方法时,一定要注意考虑边界情况!class Solution { public double findMedianSortedArr原创 2017-12-07 22:14:23 · 115 阅读 · 0 评论 -
Problem12:intToRoman
整数转换成罗马数字,自己写了一个,在LeetCode上提交说超时了,又参考别人的做了修改才好,记下来:package pratice.leetcode;import java.util.*;public class problem12 { public static String intToRoman(int num) { if(num3999) return null; //转载 2017-12-07 20:17:03 · 129 阅读 · 0 评论 -
Problem9:Palindrome Int
判断回文数,之前写过的方法太啰嗦了,这里找到一个别人优化过的,忘记留从哪找的了,所以记录下来:package pratice.leetcode;public class problem9 { public static boolean isPalindrome(int x){ if(x<0||(x%10==0&&x!=0)){ return false; } int r转载 2017-12-07 19:58:20 · 148 阅读 · 0 评论 -
problem7:reverse Integer
继续整理,简单的题也有需要注意的点:这道题里需要注意的是整数翻转后有可能溢出,需要对最后的结果扩大范围。package pratice.leetcode;public class problem7 { public static long reverse(int x) { long result=0; while(true){ int n=x%1原创 2017-12-07 19:33:15 · 134 阅读 · 0 评论 -
Problem3:lengthOfLongestSubstring
这道题通过看别人的,看到了很多不一样的实现方法,现在把它都记录下来,有更好的方法的欢迎初学者一起探讨交流哦~~~~package pratice.leetcode;import java.util.*;public class problem3 { //Time complexity : O(n^3).// public static boolean allUnique(String原创 2017-12-07 15:47:14 · 319 阅读 · 0 评论 -
Problem2:addTwoNumbers
把这两天写的题都记录下来,刚开始做LeetCode的题,解法也不高级,有更好的解法再回来补充,每天学习一点点~~~~package pratice.leetcode;public class problem2 { public static ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode result原创 2017-12-07 15:43:12 · 163 阅读 · 0 评论 -
Problem1:twoSum
练习笔记供自己查找方便,有人有更好的解法,一起交流学习哈~~~~package pratice.leetcode;import java.util.*;public class problem1 { //复杂度O(n^2) public static int[] twoSum(int[] nums, int target) { int[] result=new int[2];原创 2017-12-07 15:38:44 · 119 阅读 · 0 评论 -
Problem8:String to Integer (atoi)
考虑情况不全面,在LeetCode上一直提交不通过,参考别人的解答方案。题目要求如下:1. 首先需要丢弃字符串前面的空格;2. 然后可能有正负号(注意只取一个,如果有多个正负号,那么说这个字符串是无法转换的,返回0。比如测试用例里就有个“+-2”);3. 字符串可以包含0~9以外的字符,如果遇到非数字字符,那么只取该字符之前的部分,如“-00123a66”返回为“-转载 2017-12-12 10:57:00 · 146 阅读 · 0 评论 -
Problem14. Longest Common Prefix
题目:Write a function to find the longest common prefix string amongst an array of strings.class Solution { public String longestCommonPrefix(String[] strs) { if(strs.length=原创 2017-12-08 15:53:31 · 119 阅读 · 0 评论 -
Problem13. Roman to Integer
题目:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.class Solution { public int romanToInt(String s) { if(s==null||s.le原创 2017-12-08 15:51:18 · 97 阅读 · 0 评论 -
Problem5:Longest Palindromic Substring
看了好几遍才整明白的解法,先整理出来,留着后面忘记了可以翻看~~~~~~~~题目:Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: "babad"Output原创 2017-12-08 15:47:16 · 105 阅读 · 0 评论