Skip to content

Commit 89886c5

Browse files
authored
Renamed packages
1 parent 6da45b9 commit 89886c5

File tree

335 files changed

+10326
-4280
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

335 files changed

+10326
-4280
lines changed

.github/workflows/php.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v3
1616

1717
- name: Validate composer.json and composer.lock
1818
run: composer validate --strict
1919

2020
- name: Cache Composer packages
2121
id: composer-cache
22-
uses: actions/cache@v2
22+
uses: actions/cache@v3
2323
with:
2424
path: vendor
2525
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
@@ -31,6 +31,3 @@ jobs:
3131
- name: Run test suite
3232
run: vendor/bin/phpunit
3333

34-
- name: phpunit-coverage-badge
35-
uses: timkrase/[email protected]
36-

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
"license": "MIT",
55
"autoload": {
66
"psr-4": {
7-
"Javadev\\LeetCodePhp\\": ""
7+
"\\": "src/Algorithms/s0001_two_sum"
8+
}
9+
},
10+
"autoload-dev": {
11+
"psr-4": {
12+
"\\": "tests"
813
}
914
},
1015
"authors": [

phpunit.xml.dist

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
convertWarningsToExceptions="true"
1010
processIsolation="false"
1111
stopOnFailure="false">
12+
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
13+
<include>
14+
<directory suffix=".php">./testsdirectory>
15+
include>
16+
<report>
17+
<clover outputFile="build/logs/clover.xml"/>
18+
report>
19+
coverage>
1220
<testsuites>
1321
<testsuite name="Test Suite">
1422
<directory suffix=".php">./testsdirectory>
@@ -17,7 +25,7 @@
1725

1826
<filter>
1927
<whitelist>
20-
<directory suffix=".php">./srcdirectory>
28+
<directory suffix=".php">./testsdirectory>
2129
whitelist>
2230
filter>
2331
phpunit>

src/Algorithms/Calculator.php

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
class Solution {
2-
3-
/**
4-
* @param Integer[] $nums
5-
* @param Integer $target
6-
* @return Integer[]
7-
*/
8-
function twoSum($nums, $target) {
9-
$map = [];
10-
for ($i = 0; $i < count($nums); $i++) {
11-
$map[$nums[$i]] = $i;
12-
}
13-
for ($i = 0; $i < count($nums); $i++) {
14-
$complement = $target - $nums[$i];
15-
if (array_key_exists($complement, $map) && $map[$complement] != $i) {
16-
return [$i, $map[$complement] ];
17-
}
18-
}
19-
throw new IllegalArgumentException("No two sum solution");
20-
}
1+
class Solution {
2+
3+
/**
4+
* @param Integer[] $nums
5+
* @param Integer $target
6+
* @return Integer[]
7+
*/
8+
function twoSum($nums, $target) {
9+
$map = [];
10+
for ($i = 0; $i < count($nums); $i++) {
11+
$map[$nums[$i]] = $i;
12+
}
13+
for ($i = 0; $i < count($nums); $i++) {
14+
$complement = $target - $nums[$i];
15+
if (array_key_exists($complement, $map) && $map[$complement] != $i) {
16+
return [$i, $map[$complement] ];
17+
}
18+
}
19+
throw new IllegalArgumentException("No two sum solution");
20+
}
2121
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
1\. Two Sum
2+
3+
Easy
4+
5+
Given an array of integers `nums` and an integer `target`, return _indices of the two numbers such that they add up to `target`_.
6+
7+
You may assume that each input would have **_exactly_ one solution**, and you may not use the _same_ element twice.
8+
9+
You can return the answer in any order.
10+
11+
**Example 1:**
12+
13+
**Input:** nums = [2,7,11,15], target = 9
14+
15+
**Output:** [0,1]
16+
17+
**Explanation:** Because nums[0] + nums[1] == 9, we return [0, 1].
18+
19+
**Example 2:**
20+
21+
**Input:** nums = [3,2,4], target = 6
22+
23+
**Output:** [1,2]
24+
25+
**Example 3:**
26+
27+
**Input:** nums = [3,3], target = 6
28+
29+
**Output:** [0,1]
30+
31+
**Constraints:**
32+
33+
* <code>2 <= nums.length <= 10<sup>4sup>code>
34+
* <code>-10<sup>9sup> <= nums[i] <= 10<sup>9sup>code>
35+
* <code>-10<sup>9sup> <= target <= 10<sup>9sup>code>
36+
* **Only one valid answer exists.**
37+
38+
**Follow-up:** Can you come up with an algorithm that is less than <code>O(n<sup>2sup>)code> time complexity?
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
/**
2-
* Definition for a singly-linked list.
3-
* class ListNode {
4-
* public $val = 0;
5-
* public $next = null;
6-
* function __construct($val) { $this->val = $val; }
7-
* }
8-
*/
9-
class Solution {
10-
11-
/**
12-
* @param ListNode $l1
13-
* @param ListNode $l2
14-
* @return ListNode
15-
*/
16-
function addTwoNumbers($l1, $l2) {
17-
$dummyHead = new ListNode(0);
18-
$p = $l1; $q = $l2; $curr = $dummyHead;
19-
$carry = 0;
20-
while ($p != null || $q != null) {
21-
$x = ($p != null) ? $p->val : 0;
22-
$y = ($q != null) ? $q->val : 0;
23-
$sum = $carry + $x + $y;
24-
$carry = intval($sum / 10);
25-
$curr->next = new ListNode($sum % 10);
26-
$curr = $curr->next;
27-
if ($p != null) $p = $p->next;
28-
if ($q != null) $q = $q->next;
29-
}
30-
if ($carry > 0) {
31-
$curr->next = new ListNode($carry);
32-
}
33-
return $dummyHead->next;
34-
}
1+
/**
2+
* Definition for a singly-linked list.
3+
* class ListNode {
4+
* public $val = 0;
5+
* public $next = null;
6+
* function __construct($val) { $this->val = $val; }
7+
* }
8+
*/
9+
class Solution {
10+
11+
/**
12+
* @param ListNode $l1
13+
* @param ListNode $l2
14+
* @return ListNode
15+
*/
16+
function addTwoNumbers($l1, $l2) {
17+
$dummyHead = new ListNode(0);
18+
$p = $l1; $q = $l2; $curr = $dummyHead;
19+
$carry = 0;
20+
while ($p != null || $q != null) {
21+
$x = ($p != null) ? $p->val : 0;
22+
$y = ($q != null) ? $q->val : 0;
23+
$sum = $carry + $x + $y;
24+
$carry = intval($sum / 10);
25+
$curr->next = new ListNode($sum % 10);
26+
$curr = $curr->next;
27+
if ($p != null) $p = $p->next;
28+
if ($q != null) $q = $q->next;
29+
}
30+
if ($carry > 0) {
31+
$curr->next = new ListNode($carry);
32+
}
33+
return $dummyHead->next;
34+
}
3535
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2\. Add Two Numbers
2+
3+
Medium
4+
5+
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 contains a single digit. Add the two numbers and return the sum as a linked list.
6+
7+
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
8+
9+
**Example 1:**
10+
11+
![](https://assets.leetcode.com/uploads/2020/10/02/addtwonumber1.jpg)
12+
13+
**Input:** l1 = [2,4,3], l2 = [5,6,4]
14+
15+
**Output:** [7,0,8]
16+
17+
**Explanation:** 342 + 465 = 807.
18+
19+
**Example 2:**
20+
21+
**Input:** l1 = [0], l2 = [0]
22+
23+
**Output:** [0]
24+
25+
**Example 3:**
26+
27+
**Input:** l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]
28+
29+
**Output:** [8,9,9,9,0,0,0,1]
30+
31+
**Constraints:**
32+
33+
* The number of nodes in each linked list is in the range `[1, 100]`.
34+
* `0 <= Node.val <= 9`
35+
* It is guaranteed that the list represents a number that does not have leading zeros.
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
class Solution {
2-
3-
/**
4-
* @param String $s
5-
* @return Integer
6-
*/
7-
function lengthOfLongestSubstring($s) {
8-
if (strlen($s)==0) return 0;
9-
$map = [];
10-
$max = 0;
11-
for ($i=0, $j=0; $i < strlen($s); ++$i) {
12-
if (array_key_exists($s[$i], $map)){
13-
$j = max($j, $map[$s[$i]] + 1);
14-
}
15-
$map[$s[$i]] = $i;
16-
$max = max($max, $i - $j + 1);
17-
}
18-
return $max;
19-
}
1+
class Solution {
2+
3+
/**
4+
* @param String $s
5+
* @return Integer
6+
*/
7+
function lengthOfLongestSubstring($s) {
8+
if (strlen($s)==0) return 0;
9+
$map = [];
10+
$max = 0;
11+
for ($i=0, $j=0; $i < strlen($s); ++$i) {
12+
if (array_key_exists($s[$i], $map)){
13+
$j = max($j, $map[$s[$i]] + 1);
14+
}
15+
$map[$s[$i]] = $i;
16+
$max = max($max, $i - $j + 1);
17+
}
18+
return $max;
19+
}
2020
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
3\. Longest Substring Without Repeating Characters
2+
3+
Medium
4+
5+
Given a string `s`, find the length of the **longest substring** without repeating characters.
6+
7+
**Example 1:**
8+
9+
**Input:** s = "abcabcbb"
10+
11+
**Output:** 3
12+
13+
**Explanation:** The answer is "abc", with the length of 3.
14+
15+
**Example 2:**
16+
17+
**Input:** s = "bbbbb"
18+
19+
**Output:** 1
20+
21+
**Explanation:** The answer is "b", with the length of 1.
22+
23+
**Example 3:**
24+
25+
**Input:** s = "pwwkew"
26+
27+
**Output:** 3
28+
29+
**Explanation:** The answer is "wke", with the length of 3. Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.
30+
31+
**Example 4:**
32+
33+
**Input:** s = ""
34+
35+
**Output:** 0
36+
37+
**Constraints:**
38+
39+
* <code>0 <= s.length <= 5 * 10<sup>4sup>code>
40+
* `s` consists of English letters, digits, symbols and spaces.

0 commit comments

Comments
 (0)