
数据结构与算法
VicSlash
求实求真,大气大为
展开
-
数据结构与算法:交换两个数值的三种方式
方式一: public void swap(int a, int b) { int temp; temp = b; b = a; a = temp; }方式二:public void swap(int a, int b) { a = a + b; b = a - b; ...原创 2018-07-21 20:49:03 · 1311 阅读 · 0 评论 -
数据结构与算法:leetcode_852_Peak Index in a Mountain Array
Description Let’s call an array A a mountain if the following properties hold: A.length >= 3 There exists some 0 < i < A.length - 1 such that A[0] < A[1] < … A[i-1] < A[i] > A...原创 2018-07-22 20:28:32 · 176 阅读 · 0 评论 -
数据结构与算法:leetcode_557_Reverse Words in a String III
Description 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 Input: “Let’s take LeetCode ...原创 2018-08-03 20:02:25 · 183 阅读 · 0 评论 -
数据结构与算法:leetcode_476_Number Complement
Description Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.ExampleInput: 5Output: 2Explanation: The binary rep...原创 2018-07-26 21:19:54 · 175 阅读 · 0 评论 -
数据结构与算法:leetcode_867_Peak Index in a Mountain Array
Description Given a matrix A, return the transpose of A. The transpose of a matrix is the matrix flipped over it’s main diagonal, switching the row and column indices of the matrix.Example Input:...原创 2018-07-26 21:15:42 · 210 阅读 · 0 评论 -
数据结构与算法:leetcode_852_Peak Index in a Mountain Array
Description Let’s call an array A a mountain if the following properties hold: A.length &gt;= 3 There exists some 0 &lt; i &lt; A.length - 1 such that A[0] &lt; A[1] &lt; … A[i-1] &lt; A[i] &gt; A原创 2018-12-06 19:51:57 · 151 阅读 · 0 评论 -
数据结构与算法:leetcode_806_Number of Lines To Write String
Description We are to write the letters of a given string S, from left to right into lines. Each line has maximum width 100 units, and if writing a letter would cause the width of the line to exceed...原创 2018-07-21 22:37:20 · 186 阅读 · 0 评论 -
数据结构与算法:leetcode_804_Unique Morse Code Words
Description International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: “a” maps to “.-“, “b” maps to “-…”, “c” maps to “-.-.”, and s...原创 2018-07-21 22:29:49 · 223 阅读 · 0 评论 -
数据结构与算法:leetcode_771_Jewels and Stones
Description You’re given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how m...原创 2018-07-21 22:22:34 · 177 阅读 · 0 评论 -
数据结构与算法:leetcode_728_Self Dividing Numbers
Description A self-dividing number is a number that is divisible by every digit it contains.For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.Also, ...原创 2018-07-21 22:07:04 · 161 阅读 · 0 评论 -
数据结构与算法:leetcode_657_Judge Route Circle
Description Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place.The move sequence is ...原创 2018-07-21 21:59:34 · 448 阅读 · 0 评论 -
数据结构与算法:leetcode_561_ Array Partition I
Description Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as l...原创 2018-07-21 21:47:29 · 147 阅读 · 0 评论 -
数据结构与算法:leetcode_461_Hamming Distance
Description The Hamming distance between two integers is the number of positions at which the corresponding bits are different. 0 ≤ x, y < 2’31. Given two integers x and y, calculate the Hamming...原创 2018-07-21 21:30:19 · 125 阅读 · 0 评论 -
数据结构与算法:leetcode_01_Two Sum
Description 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...原创 2018-07-21 21:12:26 · 170 阅读 · 0 评论 -
数据结构与算法:不使用算数运算符求两个数的和
思路:这样需要用到位运算,是比较基础的算法题,mark一下。public int twoDataAddSmart(int a, int b) { int temp, d; while ((a & b) != 0) { temp = a ^ b; d = (a & b) << 1;// 需...原创 2018-07-21 21:01:22 · 303 阅读 · 0 评论 -
数据结构与算法:leetcode_884_Uncommon Words from Two Sentences
DescriptionWe are given two sentences A and B. (A sentence is a string of space separated words. Each word consists only of lowercase letters.)A word is uncommon if it appears exactly once in on...原创 2018-12-07 10:03:02 · 228 阅读 · 0 评论