
leetcode
zy_gyj
这个作者很懒,什么都没留下…
展开
-
leetcode4
There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:nums1 = [1, 3]nums2...原创 2018-03-15 21:53:15 · 226 阅读 · 0 评论 -
leetcode -- 最长公共前缀
class Solution: #最长公共前缀 def longestCommonPrefix(self, strs: List[str]) -> str: a = "" if not strs: return '' for i in range(len(strs[0])): f...原创 2019-06-03 14:21:58 · 166 阅读 · 0 评论 -
leetcode -- Roman number
class Solution: def romanToInt(self, s: str) -> int: if 'IV' or 'IX' or 'XL' or 'XC' or 'CD' or 'CM' in s: s= s.replace('IV','4 ') s=s.replace('IX','9 ') ...原创 2019-06-03 11:27:18 · 235 阅读 · 0 评论 -
leedcode--Palinfrome Number
class Solution: def isPalindrome(self, x: int) -> bool: y=x #当x为0,成立 if x==0: return True #当x<0或是10的倍数,不成立 if x < 0 or x%10 == 0: ...原创 2019-06-03 10:12:22 · 151 阅读 · 0 评论 -
leetcode----反转整数
Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21class Solution: de...原创 2019-06-02 23:06:58 · 119 阅读 · 0 评论 -
2019-4-7/day2 --add two numbers
题目:给定两个非负整数的链表。数字以相反的顺序存储,每个节点包含一个数字。将这两个数字相加,并作为链表返回Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)Output: 7 -> 0 -> 8Explion: 342 + 465 = 807.思路:先将两个链表均表示为数字,数字进行相加,再将数字转换为链表输出直接...原创 2019-04-07 13:44:09 · 134 阅读 · 0 评论 -
2019-4-6/ day1--two sum python
题目:输入一个数组和target,要在一个数组中找到两个数字,其和为target,从小到大输出数组中两个数字的位置。给定数组:nums = [2, 7, 11, 15], 数值:target = 9,使得:nums[0] + nums[1] = 2 + 7 = 9,返回:return [0, 1]暴力搜索--循环,时间复杂度n*nclass Solution(object):...原创 2019-04-06 19:12:57 · 150 阅读 · 0 评论 -
pascal's triangle
给定索引k,返回帕斯卡三角形的第k行。例如,给定k = 3,返回[1,3,3,1]。注意:您可以优化您的算法以仅使用O(k)额外空间吗? public static List<Integer> getRow(int rowIndex) { List<Integer> row = new ArrayList<Integer>(); ...原创 2018-03-21 20:30:02 · 159 阅读 · 0 评论 -
leetcode7 Plus One
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digits are s...原创 2018-03-20 16:51:19 · 221 阅读 · 0 评论 -
leetcode3
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with the l...原创 2018-03-13 19:46:33 · 355 阅读 · 0 评论 -
leetcode2
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i...原创 2018-03-12 21:56:19 · 121 阅读 · 0 评论 -
leetcode9
以k个步骤向右旋转n个元素的数组。例如,当n = 7和k = 3时,数组[1,2,3,4,5,6,7]被旋转到[5,6,7,1,2,3,4]。package leetcode;public class leetcode9 { public void reverse(int[] nums,int start,int end) { while(start<end) { int temp=...原创 2018-03-22 13:52:23 · 284 阅读 · 0 评论 -
leetcode6
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Exam...原创 2018-03-18 15:23:04 · 183 阅读 · 0 评论 -
leetcode1
day1:Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the sa...原创 2018-03-11 21:36:27 · 153 阅读 · 0 评论 -
leetcode5
给定一个32位有符号整数,整数的反转数字。例1:输入: 123 输出: 321例2:输入: -123 输出: -321例3:输入: 120输出: 21public static int reverse1(int x) { long result=0; while(x!=0) { result=(result*10)+(x%10); if(result>Integ...原创 2018-03-16 16:33:59 · 449 阅读 · 0 评论 -
leetcode --- Implement strStr()
class Solution: def strStr(self, haystack: str, needle: str) -> int: if needle =="": return 0 if len(haystack) == len(needle): if haystack == needle: ...原创 2019-06-04 15:35:19 · 231 阅读 · 1 评论