
oj
文章平均质量分 58
愛桀桀
这个作者很懒,什么都没留下…
展开
-
oj 268. Missing Number
要求 Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.翻译给定一个包含n个不同数字原创 2017-04-08 10:18:13 · 159 阅读 · 0 评论 -
oj541. Reverse String II
Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of th原创 2017-04-22 09:45:51 · 248 阅读 · 0 评论 -
oj557. Reverse Words in a String III
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: "Let's take LeetCode contes原创 2017-04-22 10:16:41 · 185 阅读 · 0 评论 -
oj520. Detect Capital
iven a word, you need to judge whether the usage of capitals in it is right or not.We define the usage of capitals in a word to be right when one of the following cases holds:All letters in th原创 2017-05-13 11:32:48 · 260 阅读 · 0 评论 -
oj383. Ransom Note
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; ot原创 2017-04-24 15:42:24 · 248 阅读 · 0 评论 -
oj20. Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va原创 2017-04-24 10:34:26 · 182 阅读 · 0 评论 -
oj67. Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".翻译:给定两个二进制字符串,返回它们的和(也是一个二进制字符串)。例如,a = "11"b = "1"Return "100"。原创 2017-05-15 17:20:51 · 190 阅读 · 0 评论 -
oj66. 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 digi原创 2017-04-09 15:47:13 · 551 阅读 · 0 评论 -
434. Number of Segments in a String
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.Please note that the string does not contain any non-printable characters.原创 2017-04-25 11:01:08 · 166 阅读 · 0 评论 -
1. Two Sum
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 sam原创 2017-05-16 20:18:29 · 137 阅读 · 0 评论 -
oj459. Repeated Substring Pattern
回家休息了小半个月,荒废了不少,今天继续。Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string co原创 2017-05-08 18:17:04 · 165 阅读 · 0 评论 -
409. Longest Palindrome
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.This is case sensitive, for example "Aa" is not con原创 2017-05-18 18:19:41 · 138 阅读 · 0 评论 -
oj350. Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].Note:Each element in the result should appear as ma原创 2017-05-31 20:38:19 · 251 阅读 · 0 评论 -
oj485. Max Consecutive Ones
Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutiv原创 2017-04-08 11:30:29 · 206 阅读 · 0 评论 -
oj28. Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.翻译:实现strStr()函数返回needle在haystack中的首个索引位置思路:最懵逼的用indexOf函数解决了原创 2017-05-11 21:19:24 · 208 阅读 · 0 评论 -
oj125. Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a原创 2017-04-21 10:20:39 · 225 阅读 · 0 评论 -
oj26. Remove Duplicates from Sorted Array
Given a sorted array, 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 in place with原创 2017-04-10 11:14:53 · 165 阅读 · 0 评论 -
oj27. Remove Element
Given an array and a value, 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 in place with constant memory.原创 2017-04-11 10:55:00 · 158 阅读 · 0 评论 -
oj122. Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on原创 2017-04-11 20:12:08 · 180 阅读 · 0 评论 -
oj217. Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element原创 2017-04-12 11:04:17 · 198 阅读 · 0 评论 -
oj219. Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is a原创 2017-04-12 18:26:32 · 235 阅读 · 0 评论 -
oj160. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘原创 2017-04-18 15:21:15 · 236 阅读 · 0 评论 -
oj141. Linked List Cycle
Given a linked list, determine if it has a cycle in it.翻译:给定一个链表,确定它是否有一个循环。超时思路:新建一个list来装链表节点,若新节点指向的下一个节点已经存在list中,则返回真 public boolean hasCycle(ListNode head) { List l = new ArrayLi原创 2017-04-14 10:40:17 · 142 阅读 · 0 评论 -
oj203. Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5翻译:从具有val值的整数的链接列表中删原创 2017-04-18 16:43:47 · 204 阅读 · 0 评论 -
oj237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2017-04-14 15:48:23 · 159 阅读 · 0 评论 -
oj83. Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.翻译:给定一个排序的链接列表,删除原创 2017-04-14 20:37:29 · 146 阅读 · 0 评论 -
oj206. Reverse Linked List
Reverse a singly linked list.翻译: 反转单链接列表。思路:单链表节点无法知道前一节点,所以需要一个节点类记录前节点,同时当前结点指向上一节点后,原来指向的节点信息就丢失了,顾需要一个节点类保存下一节点。总共需要三个节点。public ListNode reverseList(ListNode head) { ListNode pre = nul原创 2017-04-20 11:00:59 · 153 阅读 · 0 评论 -
oj234. Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.翻译:给定一个单链表,确定它是否是回文。思路:一开始的思路不是很清晰,觉得比较复杂,后来看了答案,思路差不多。就是先算链表的长度,再把链表从中间分成两部分,把后半部分反转,再对比两个链表。public boolean isPalindrome(ListNode hea原创 2017-04-20 16:08:37 · 188 阅读 · 0 评论 -
oj14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.翻译:编写一个函数来查找字符串数组中最长的公共前缀字符串。思路:英语不太好,题意一开始没有理解清楚,错误理解为找出字符串数组中最大的共同前缀,即只要有任意两个满足条件即可,代码如下,由于无法提交进行所有测试,所以代码肯定原创 2017-05-10 21:30:28 · 168 阅读 · 0 评论 -
oj121. Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),原创 2017-04-09 10:33:02 · 172 阅读 · 0 评论