02 2017 档案
摘要:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?题意:判断链表是否成环。注意:最后一个节点的next指针,有可能指向链表中任意一个节点方法一:使用HashSet,保存遍历过的节点的HashCodepublic class Solut...
阅读全文
摘要:You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins.Given n, find the total number of full staircase rows that can be formed.n is a n...
阅读全文
摘要:public getRandomArr(num:number): number[]{ var array:number[] = new Array; //给原始数组original赋值 var i :number; for(i= 0;i < num;i++) { array[i] = i; }// 打乱数组...
阅读全文
摘要:function(str){ var realLength = 0, len = str.length, charCode = -1; for (var i = 0; i = 0 && charCode <= 128) { realLength += 1; } else { realLength += 2; ...
阅读全文
摘要:function(num) { var number = parseFloat(num)*100; return parseInt(number+0.5)/100;};null
阅读全文
摘要:static public void DeleteFolder(string dir){ int num = 0; foreach (string d in Directory.GetFileSystemEntries(dir)) { if (File.Exists(d)) { FileInfo fi = new FileInfo...
阅读全文
摘要:Given 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 this word...
阅读全文
摘要:Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 题意:构造杨辉三角static public List> Generate...
阅读全文
摘要: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.Examp...
阅读全文
摘要: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...
阅读全文
摘要: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.The orde...
阅读全文
摘要:static public void DeleteRepeatChar(string s){ Dictionary d = new Dictionary(); foreach (var c in s){ int num = 0; if (d.TryGetValue(c, out num)){ d[c] += 1; ...
阅读全文
摘要:Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Given s = "hello", return "holle".Example 2:Given s = "leetcode", return "leotcede"题意:反转字符串中元音字母的位置方法1:用...
阅读全文
摘要:Given a positive integer num, write a function which returns True if num is a perfect square else False.Note: Do not use any built-in library function such as sqrt.Example 1:Input: 16 Returns: True Ex...
阅读全文
摘要:You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house...
阅读全文
摘要:Given an integer (signed 32 bits), write a function to check whether it is a power of 4.Example:Given num = 16, return true. Given num = 5, return false.Follow up: Could you solve it without loops/rec...
阅读全文
摘要:Given an integer, return its base 7 string representation.Example 1:Input: 100 Output: "202" Example 2:Input: -7 Output: "-10" Note: The input will be in range of [-1e7, 1e7].public class Solution { ...
阅读全文
摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1] has the ...
阅读全文
摘要:Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: "Gold Medal", "Silver Medal" and "Bronze Medal".Example 1:Input: [5,...
阅读全文
摘要:Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below.Input: ["Hello", "Alaska", "Dad", "Peace"] Output: ["Ala...
阅读全文
摘要:You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1's elements in the corresponding places of nums2.Th...
阅读全文
摘要: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 one an...
阅读全文
摘要: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.Here...
阅读全文
摘要: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.给定一个包含从0, 1, 2, ..., n, 选出的n个不同数字的数组,从中...
阅读全文
摘要: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 same el...
阅读全文
摘要:Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers su...
阅读全文