leetcode刷题记录
文章平均质量分 63
make_a_great_effort
IT小白
展开
-
reverseBits
Reverse bits of a given 32 bits unsigned integer. For example: given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010...原创 2018-09-15 20:33:36 · 90 阅读 · 0 评论 -
Remove Element
Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input arra...原创 2018-09-20 21:40:22 · 147 阅读 · 0 评论 -
Remove Duplicates from Sorted Array II
Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length. Do not allocate extra space for another array, you must do this by mod...原创 2018-09-21 10:55:03 · 84 阅读 · 0 评论 -
Remove Duplicates from Sorted Array
Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this by modifyi...原创 2018-09-21 11:25:56 · 75 阅读 · 0 评论 -
Monotonic Array
An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is monotone increasing if for all i <= j, A[i] <= A[j]. An array A is monotone decreasing if for al...原创 2018-09-21 15:29:52 · 113 阅读 · 0 评论 -
Add Binary
Given two binary strings, return their sum (also a binary string). The input strings are both non-empty and contains only characters 1 or 0. class Solution { public String addBinary(String a,...原创 2018-10-08 18:27:37 · 76 阅读 · 0 评论 -
Plus One
Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stored such that the most significant digit is at the head of the list, and each element...原创 2018-10-08 18:56:31 · 92 阅读 · 0 评论 -
唯一摩尔斯密码词
国际摩尔斯密码定义一种标准编码方式,将每个字母对应于一个由一系列点和短线组成的字符串, 比如: "a" 对应 ".-", "b" 对应 "-...", "c" 对应 "-.-.", 等等。 为了方便,所有26个英文字母对应摩尔斯密码表如下: [".-","-...","-.-.","-..","原创 2018-10-29 14:40:39 · 216 阅读 · 0 评论 -
写字符串需要的行数 NumberofLinesToWriteString
我们要把给定的字符串 S 从左到右写到每一行上,每一行的最大宽度为100个单位,如果我们在写某个字母的时候会使这行超过了100 个单位,那么我们应该把这个字母写到下一行。我们给定了一个数组 widths ,这个数组 widths[0] 代表 'a' 需要的单位, widths[1] 代表 'b' 需要的单位,..., widths[25] 代表 'z' 需要的单位。 现在回答两个问题:至少多少行...原创 2018-10-29 14:58:57 · 136 阅读 · 0 评论 -
Implement strStr
Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Clarification: What should we return when needle is an empty string? This is a great question...原创 2018-09-20 10:11:14 · 87 阅读 · 0 评论 -
Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of b...原创 2018-09-20 09:42:32 · 57 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. 重点是空字符串和字符串全为同一个字符的情况 class Solution { public int lengthOfLongestSubstring(String s) { int count ...原创 2018-09-15 20:34:52 · 56 阅读 · 0 评论 -
Count and Say
/* * 题目的关键就是搞懂题意,数上个n对应的数字: * 当n=1结果是 1; * 当n=2结果是 1个1,结果就是21; * 当n=3结果是 1个2,1个1,结果就是1211; * 当n=4结果是 1个1,1个2,2个1,结果就是111221; * 以此类推 * 解题的关键就是数重复出现的个数,遇到不同的数字就重新数...原创 2018-09-16 20:46:30 · 153 阅读 · 0 评论 -
Palindrome Number
水仙花数的问题 可以先求反转的数,在与原来的数字相比较 在java中用string和stringbuffer的内置方法可以快速求解 public static boolean isPalindrome(int x) { String str = String.valueOf(x); String st = new StringBuffer(s...原创 2018-09-16 20:49:39 · 62 阅读 · 0 评论 -
Regular Expression Matching
Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. ...原创 2018-09-19 08:56:10 · 64 阅读 · 0 评论 -
Add Two Numbers
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-09-14 16:54:12 · 71 阅读 · 0 评论 -
859.Buddy Strings
Given two strings A and B of lowercase letters, return true if and only if we can swap two letters in A so that the result equals B 给定两个字符串,如果只交换其中两个字符的位置就能使两个字符串相同,则返回true. 思路: 1. 首先两个字符串的长度必定大于2而...原创 2018-09-19 19:35:55 · 87 阅读 · 0 评论 -
Single Number 问题(共三个)
Single Number I Given a non-empty array of integers, every element appears twice except for one. Find that single one. 给定一个数组,其中所有的元素均出现两次除了其中的某一个,请找出那个只出现一次的元素。 思路:将所有的元素挨个放入列表中,如果该元素在列表中已经存在了,那么就...原创 2018-09-19 22:01:22 · 124 阅读 · 0 评论 -
Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. 给定一个字符串,判定它是否是会问字符串,只考虑数字字母字符并且忽略大小写。 思路:将字符串中的所有非数字字母字符均去掉,组成新的字符,查看新的字符是否是回文字符 pub...原创 2018-09-20 09:16:10 · 72 阅读 · 0 评论 -
子域名访问计数 Subdomain Visit Count
一个网站域名,如"discuss.leetcode.com",包含了多个子域名。作为顶级域名,常用的有"com",下一级则有"leetcode.com",最低的一级为"discuss.leetcode.com"。当我们访问域名"discuss.leetcode.com"时,也同时访问了其父域名"leetcode.com"以及顶级域名 "com"。 给定一个带访问次数和原创 2018-10-29 17:41:43 · 108 阅读 · 0 评论