Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: trekhleb/javascript-algorithms
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: hushicai/javascript-algorithms
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 2 commits
  • 4 files changed
  • 2 contributors

Commits on Jun 4, 2019

  1. feat(string): 添加回文串递归算法

    hushicai authored and hushicai committed Jun 4, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    8955e5c View commit details

Commits on Jun 6, 2019

  1. fix wrong spell

    hushicai committed Jun 6, 2019
    Copy the full SHA
    dd8e110 View commit details
3 changes: 3 additions & 0 deletions src/algorithms/string/is-palindrome/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 回文串

递归算法
11 changes: 11 additions & 0 deletions src/algorithms/string/is-palindrome/__tests__/isPalindrome.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import isPalindrome from '../isPalindrome';

describe('isPalindrome', () => {
it('should be a palindrome string', () => {
expect(isPalindrome('level')).toBe(true);
expect(isPalindrome('noon')).toBe(true);
});
it('should not be a palindrome string', () => {
expect(isPalindrome('devel')).toBe(false);
});
});
14 changes: 14 additions & 0 deletions src/algorithms/string/is-palindrome/isPalindrome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default function isPalindrome(str) {
const len = str.length;
const first = str[0];
const last = str[str.length - 1];

if (len === 0 || len === 1) {
return true;
}

if (first === last) {
return isPalindrome(str.substring(1, str.length - 1));
}
return false;
}
2 changes: 1 addition & 1 deletion src/data-structures/priority-queue/PriorityQueue.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import Comparator from '../../utils/comparator/Comparator';
// we take into account its priority instead of the element's value.
export default class PriorityQueue extends MinHeap {
constructor() {
// Call MinHip constructor first.
// Call MinHeap constructor first.
super();

// Setup priorities map.